Program to reverse a given number

C Programming Language / Loop control in C Language

1442

Program:

#include<stdio.h>
void main()
{
int n,a,r=0;
 
printf("enter any no to get its reverse: ");
scanf("%d",&n);
	while(n>=1)
	{
	a=n%10;
	r=r*10+a;
	n=n/10;
	}
printf("reverse=%d \n",r);
 
}

Output:

enter any no to get its reverse: 123
reverse=321
Press any key to continue . . .

Explanation:

In this program, user will give a number and it will give a reverse of that number like 456 to 654

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.