C program to find reverse of a number

Preview
You must first complete for statement in c language | Nesting of for in c language | for loop in C before viewing this Lesson

C program to find reverse of a number

#include<stdio.h>
#include<conio.h>
int main()
{
int m,n,r;
printf(“\nEnter a number:=”);
scanf(“%d”,&n); //123
r=0;
while(n>0)
{
m=n%10; //3 2 1
r=r*10+m; //3 32 321
n=n/10; //12 1 0
}
printf(“\nReverse=%d”,r);
getch();

return  0;
}

Explanation
/*
n=123
r=0
m=3
r=3
n=12
m=2
r=32
n=1
m=1
r=321
n=0
*/



Spread the love
Back to: C Programming Language
Spread the love