C-programming - Reversina a number in C, C program for reversing a number

Reversina a number in C

This program reverses the given number. For example if user enter 78 as input then 87 is printed as output. Modulus operator is used for obtaining the digits one by one.

#include<stdio.h>
#include<conio.h>
 
main()
{
   int n, rev = 0;
 
   printf("Enter a number to reverse\n");
   scanf("%d",&n);
 
   while( n != 0 )
   {
      rev = rev * 10;
      rev = rev + n%10;
      n = n/10;
   }
 
   printf("Reverse of entered number is = %d\n", revh                                                     );
 
   return 0;
}


In this program, the input is got from the user. Now a while loop is executed to reverse a number. Initial condition that given value not equal to 0 is checked. Then the individual digits are obtained using modulo operator. now the number is printed in reverse order.

output


Enter a number to reverse
567
Reverse of entered number is =
765


The topic on C-programming - Reversina a number in C is posted by - Sandhya

Hope you have enjoyed, C-programming - Reversina a number in CThanks for your time

Tech Bluff