c program to reverse a number using for loop

Program

C Program to reverse digits of a number using for loop

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

  printf("\n reverse of number is = %d",rever); 
  getch();
}  

Output

Enter a number: 132
reverse of number is = 231

 

Leave a Reply

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