Advertisement
Josif_tepe

Untitled

Nov 12th, 2021
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int z, c;
  8.     cin >> z >> c;
  9.     int najmal, najgolem;
  10.     najmal = 1;
  11.     for(int i = 0; i < c-1; i++)
  12.     {
  13.         najmal *= 10;
  14.     }
  15.     najgolem = (najmal * 10) - 1;
  16.     int broj;
  17.     int zbir;
  18.     for(int i = najmal; i < najgolem; i++)
  19.     {
  20.         broj = i;
  21.         zbir = 0;
  22.         while(broj > 0)
  23.         {
  24.             zbir += broj;
  25.             broj /= 10;
  26.         }
  27.         if(z == zbir)
  28.         {
  29.             cout << i << endl;
  30.             return 0;
  31.         }
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement