Following is a program to reverse a five-digit number :
#include <stdio.h>
int main() {
int n,a,b,c,d,e;
printf("Enter a five digit number ");
scanf("%d",&n);
a = n/10000;
b = n/1000 - a*10 ;
c = n/100 - a*100 - b*10 ;
d = n/10 - a*1000 - b*100 - c*10 ;
e = n - a*10000 - b*1000 - c*100 - d*10;
printf("%d",e*10000 + d*1000 + c*100 + b*10 + a);
return 0;
}
Explanation:
- Input Prompt:
printf("Enter a five-digit number: ");prompts the user to enter a five-digit number. - Reading Input:
scanf("%d", &n);reads the input number. - Extracting Digits:
a = n / 10000;extracts the first digit.b = (n / 1000) % 10;extracts the second digit.c = (n / 100) % 10;extracts the third digit.d = (n / 10) % 10;extracts the fourth digit.e = n % 10;extracts the fifth digit.
- Printing the Reversed Number:
printf("Reversed number: %d", e * 10000 + d * 1000 + c * 100 + b * 10 + a);prints the reversed number.
