#include<stdio.h>
#include<conio.h>
main(){
int n,i,rev=0,q,r;
clrscr();
printf("Enter an integer number\n");
scanf("%d",&n);
if (n>0){
q=n;
while (q!=0){
r=q%10;
q=q/10;
rev=rev*10+r;
}
printf("Reverse of given number %d = %d.\n",n,rev);
}
else printf("Wrong input\n");
getch();
return 1;
}
Here is a program to reverse a number in C using recursion.
ReplyDeletegetReversedNumber(1234) = (4*1000) + getReversedNumber(123)