Reverse a Number in C Using While Loop

Reverse number in c. This program is to reverse the number and print in the output screen in c programming. To print the number in reverse using the while loop in c language.

#include <stdio.h>
int main()
int n, rev = 0, rem;
printf("Enter the number ");
scanf("%d", &n);
while (n != 0)
rem = n % 10;
rev = rev * 10 + rem;
n /= 10;
printf("reversed number is %d", rev);
return 0;



Enter the number 56789

reversed number is 98765

While Loop and How to Reverse a Number in C

A pre-tested loop is also known as a while loop. A while loop, in general, allows a section of code to be performed many times based on a boolean state. It can be thought of as a looping if statement. The while loop is typically employed when the number of iterations is unknown ahead of time.

Return Statement in C

return 0 – As previously stated, the function main returns an integer value (int main()), hence we are returning 0 in this case. It signals that our program has completed correctly, and we use this return statement to end our main function.

Not Equal Symbol in C

Checks whether the values of two operands are equal. If the values are not equal, the condition is met. 

Modulo Operator in C

The modulo operator, represented by the symbol percent, is an arithmetic operator. The remainder of an integer division is produced by the modulo division operator. Using this program we can execute the reverse number in c.