Home / Programs / Program to reverse a given number
Programming Example

Program to reverse a given number

👁 1,466 Views
💻 Practical Program
📘 Step by Step Learning
In this program, user will give a number and it will give a reverse of that number like 456 to 654

Program Code

#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

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.