27 lines
489 B
C
27 lines
489 B
C
#include <stdio.h>
|
|
|
|
int main(void) {
|
|
int n;
|
|
|
|
printf("Integer n: ");
|
|
scanf("%d", &n);
|
|
|
|
// Throw error when n is not in range of 100 <= n <= 999
|
|
if (n < 100 || n > 999) {
|
|
printf("Integer n must be 3 digit number");
|
|
return 1;
|
|
}
|
|
|
|
int a, b, c, m; // a * 10^2 + b * 10^1 + c * 10^0 = n
|
|
|
|
a = n / 100;
|
|
b = n / 10 % 10;
|
|
c = n % 10;
|
|
|
|
m = c * 100 + b * 10 + a; // m is reversed n
|
|
|
|
printf("Reversed integer is %d.", m);
|
|
|
|
return 0;
|
|
}
|