Program to reverse a number in C[Easy Method]

Program to reverse a number in C is easy if you know loops. Here, I will explain to you all the steps one by one.

Let’s begin.

Program to reverse a number in C

Program to reverse a number in C

#include<stdio.h>
#include<conio.h>

void main()
{
int n,r,b=0;
clrscr();
printf("Enter any number to reverse");
scanf("%d",&n);

while(n>0)
{
r=n%10;
b=b*10+r;
n=n/10;
}

printf("Reverse or number is =%d",b);
getch();
}

Program Code Explanation (PCE)

  • Input any number from user to reverse.
  • start and repeat a while loop that breaks when n<=0
  • calculate reminder(r) by dividing n%10
  • initially, we store 0 in b then we use b=b*10+r formula; this formula make a new number that will be reverse of user-defined number(n)
  • Print the value of b as a reverse number.

So, you understand the program to reverse a number in C

Other useful programs

If you have a question please ask me in below comment section. Don’t forget to share this program in your social family and friends.

Leave a Comment

error: Don\'t make piracy - Write your own content :)