C program to print reverse of a number using while loop

C program to print reverse of a number using while loop. 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

What is while loop and how to reverse a number

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.

What is return statement in c program

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.