Home » C Programs » Reverse the Number in C

Reverse the 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 the number 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 reverse the number in c

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. 

Reverse the Number in C

//reverse the number in c
#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 

Enter the number 56789

reversed number is 98765