Advertisement
Josif_tepe

Untitled

Oct 6th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int poramni(int broj) {
  6.     if(broj == 0) {
  7.         return 0;
  8.     }
  9.     int cifra = broj % 10;
  10.     return poramni(broj / 10) * 10 + cifra;
  11. }
  12. int main()
  13. {
  14.  
  15.     int x;
  16.     cin >> x;
  17.     cout << poramni(x) << endl;
  18.     return 0;
  19. }
  20. // poramni(456) = poramni(45) * 10 + 6 = 45 * 10 + 6 = 456
  21. // poramni(45) =  poramni(4) * 10 + 5 = 4 * 10 + 5 = 45
  22. // poramni(4) =   poramni(0) * 10 + 4 = 0 * 10 + 4 = 4
  23. // poramni(0) = 0
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement