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.

   int n, rev = 0;
   printf("Enter a number to reverse\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.


Enter a number to reverse
Reverse of entered number is =

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