Skip to content
Home » C Programs » Reverse a Number in C Using While Loop

Reverse a Number in C Using While Loop

Basic c program to find reverse of a number. 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.

While Loop Definition 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. Looping statement is important method to execute the c program to find reverse of a number.

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. 

C Program to Find Reverse of a Number

//c program to find reverse of a number
#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;

Output of c program to find reverse of a number:

Enter the number 56789

reversed number is 98765