c program to reverse a number using while loop

Program

Program to reverse digits of a number using while loop in c

#include<stdio.h>
#include<conio.h>
void main()
{
  int num;
  int rev=0, rem=0;
  printf("n Enter a number: ");
  scanf("%d",&num);
  while(num>0)
  {
    rem = num%10;
    rev = rev*10+rem;
    num = num/10;
  }
  printf("n reverse number = %d",rev);
  getch();
} 

Output

Enter a number: 123
Reverse number = 321

Leave a Reply

error: Content is protected !!
%d bloggers like this: