BUPT-homework/semester1/pset5/2-swap.c

33 lines
525 B
C
Raw Normal View History

2021-10-25 20:25:25 +08:00
#include <stdio.h>
// Function prototypes
void swap(int *a, int *b);
int main(void) {
// Initialize variables
int n;
int length = 0;
int nums[10];
// Get input
scanf("%d", &n);
// Tabulate nums[]
while (n > 0) {
nums[length] = n % 10;
n /= 10;
length++;
}
// See if anything is wrong
if (nums[0] == 0) {
printf("The number cannot be changed.\n");
} else { // Print answer
for (int i = 0; i < length; i++) {
printf("%i", nums[i]);
}
printf("\n");
}
return 0;
}