C Program
to reverse a number
This is a C program to reverse a number. In this example, it
takes the a number as input to the
program, reverses the number and stores in another variable and prints the
result.
See the
source code of the program
/*
Program to reverse a number
input : a number
output : reverse of the number
*/
#include <stdio.h>
#include <conio.h>
int main() {
int n, reverse = 0;
printf("Enter a number to reverse:");
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);
getch();
return 0;
}
Output
No comments:
Post a Comment