How to reverse a given number using C


#include <stdio.h>

 int main() {
   int num, rem, rev = 0;

   printf("\nEnter any no to be reversed : ");
   scanf("%d", &num);

   while (num >= 1) {
      rem = num % 10;
      rev = rev * 10 + rem;
      num = num / 10;
   }

   printf("\nReversed Number : %d", rev);
   return (0);
}

Output :


Enter any no to be reversed : 123
Reversed Number : 321
How to reverse a given number using C

Published on 16-Dec-2021 15:56:34

You may also like this!