C Program to reverse an integer number using for
Program
#include<stdio.h>
int reverseInt(int num)
{
int i,remainder,rev=0;
for(i=num;i>0; )
{
remainder=i%10;
rev=rev*10+remainder;
i=i/10;
}
return rev;
}
int main()
{
int num;
printf("Enter an Integer: ");
scanf("%d",&num);
printf("Reversed number: %d", reverseInt(num));
return 0;
}
Output
$ gcc reverse-integer-number-using-for.c
$ ./a.out
Enter an Integer: 57891
Reversed number: 19875