C Program to find Reverse of a Number

Reversing a number can be done in 3 simple steps. 

1. Find the remainder using %, you will get the last digit of a number, r = num % 10.

2. rev = rev * 10 + r will append r to rev. After all the iterations, the final reverse number will be saved in rev.

3. Find the remaining number using num = num / 10

//program name: Reverse_of_Number.c
#include<stdio.h>
 int main()
 {
   int num,r,rev=0;
   printf("Enter a number to find reverse: ");
   scanf("%d",&num);
   while(num)
   {
     r=num%10;
     rev=rev*10+r;
     num=num/10;
   }
   printf("Reversed of given number: %d",rev);
   return 0;
 }

OUTPUT:

Enter a number to find reverse: 1234
Reversed of given number: 4321

Leave a Reply

Your email address will not be published. Required fields are marked *