fork download
  1. // C Programs to Calculate
  2. // reverse of a number
  3. #include <stdio.h>
  4.  
  5. int reverse(int n, int ans)
  6. {
  7. if (n == 0)
  8. return ans;
  9.  
  10. ans = ans * 10 + n % 10;
  11. return reverse(n / 10, ans);
  12. }
  13.  
  14. int main()
  15. {
  16. int N = 110101;
  17. printf("Initial number:%d\n", N);
  18.  
  19. // N = reverse_iteration(N);
  20. //printf("%d after reverse using iteration\n", N);
  21.  
  22. int ans = 0;
  23. ans = reverse(N, ans);
  24. printf("%d after again reverse using recursion", ans);
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 5320KB
stdin
45
stdout
Initial number:110101
101011 after again reverse using recursion