marwanpro

tp2 -- part reverse

Sep 19th, 2016
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. #include <time.h>
  5. #include <stdlib.h>
  6. #define SPACE " "
  7.  
  8. using namespace std;
  9.  
  10. // Init Void
  11. int reverser(int n);
  12.  
  13. int main(void)
  14. {
  15.     int input, output;
  16.     cout << "Entrer l'entier a inverser: ";
  17.     cin >> input;
  18.     output = reverser(input);
  19.     cout << output << endl;
  20.     system("pause");
  21.     return 0;
  22. }
  23.  
  24. int reverser(int n)
  25. {
  26.     int result = 0;
  27.     while (n > 10)
  28.     {
  29.         result += n % 10;
  30.         n /= 10;
  31.         result *= 10;
  32.     }
  33.     result += n;
  34.     return result;
  35. }
Add Comment
Please, Sign In to add comment