C program to find reverse of a number

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

C program to find reverse of a number

#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,r;
clrscr();
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();
}

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

Best Books of Computer Science

Back to: C Programming Language