Home C Programming Language / Programs / Program to reverse a given number
🚀 Programming Example

Program to reverse a given number

👁 1,467 Views
💻 Practical Program
📘 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);
 
}

                        

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.