Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int back[20];
- int reverse(int number, int digits)
- {
- int remainder = number%10;
- back[digits++] = remainder;
- number /= 10;
- if(number) reverse(number, digits);
- else{
- int j = 0, total = 0;
- for(int i=0; i < digits; i++)
- total += back[digits-1-i] * pow(10,j++);
- return total;
- }
- }
- int main(){
- int number;
- printf("Enter the number you want to reverse: ");
- scanf("%d",&number);
- printf("The reverse of %d is %d", number, reverse(number, 0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement