C Program to reverse a given integer number using while loop using functions
Program
#include<stdio.h>
int reverseInt(int num)
{
int rev = 0, remainder;
while (num != 0) {
remainder = num % 10;
rev = rev * 10 + remainder;
num /= 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-while.c
$ ./a.out
Enter an Integer: 35478
Reversed number: 87453