fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int reverse(int, int);
  5.  
  6. int main()
  7. {
  8. int number = 1234567890;
  9.  
  10.  
  11. printf("Reversed number is %d\n", reverse(number, 0));
  12. return 0;
  13. }
  14.  
  15. int reverse (int n, int power) {
  16. static int reversed_number = 0;
  17. int digit = n % 10;
  18. if (n == 0) {
  19. return reversed_number;
  20. }
  21. reversed_number = digit + reversed_number * pow(10, power);
  22.  
  23.  
  24. if (power == 0) {
  25. reverse(n/10, power+1);
  26. } else {
  27. reverse(n/10, power);
  28. }
  29. }
  30.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
Reversed number is 987654321