Search This Blog

C Program to Reverse a Number - Reverse Digits of a Number using C Program

This post includes a C program to reverse a given number. That is, to reverse the order of digits. If 543 is entered, it will be displayed as 345.

C Program:

#include<stdio.h>
main()
{
int n, reverse = 0;
printf("Enter a number to reverse:\n");
scanf("%d",&n);
while (n != 0)
    {
    reverse = reverse * 10;
    reverse = reverse + n%10;
n = n/10;
    }
printf("Reverse of entered number is = %d\n", reverse);
}

No comments: