neogz

obrnuto

Feb 11th, 2014
65
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. #include <cmath>
  3. using namespace std;
  4.  
  5. int broj(int);
  6.  
  7. int main()
  8. {
  9.    
  10.     int n;
  11.     do
  12.     {
  13.         cout << "UNESI PRIRODAN BROJ N: ";
  14.         cin >> n;
  15.     } while (n<0);
  16.  
  17.     cout << "OBRNUT BROJ >> " << broj(n);
  18.  
  19.  
  20.     system("pause >null");
  21.     return 0;
  22. }
  23.  
  24. int broj(int n)
  25. {
  26.     int pom = n,brojac=0,s=0;
  27.     while (n!=0)
  28.     {
  29.         n /= 10;
  30.         brojac++;
  31.     }
  32.  
  33.  
  34.     for (int i = brojac-1; i>=0; i--)
  35.     {
  36.         s += (pom % 10)*pow(10.0, i);
  37.         pom /= 10;
  38.     }
  39.  
  40.     return s;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment