c program to reverse a number using do while loop

Program

Program in C for reversal of digits of a number using do while loop

#include
#include
void main()
{
  int val;
  int rever=0, remain=0;
  printf("\nEnter a number: ");
  scanf("\n%d",&val);
  do
  {
    remain = val%10;
    rever = rever*10+remain;
    val = val/10;
}while(val>0);

printf("\nreverse of the number = %d",rever);
getch();
}

Output

Enter a number: 254
reverse of the number = 452

Leave a Reply

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