第五课。
This commit is contained in:
23
05/Exercise03.c
Normal file
23
05/Exercise03.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int input = 0;
|
||||
int digit = 0;
|
||||
int digits[5] = {0};
|
||||
scanf("%d", &input);
|
||||
while (input != 0) {
|
||||
digits[digit] = input % 10;
|
||||
input /= 10;
|
||||
digit++;
|
||||
}
|
||||
printf("This number has %d digit(s).\n", digit);
|
||||
printf("To print every digit in a seperate line:\n");
|
||||
for (int i = digit - 1; i >= 0; i--) {
|
||||
printf("%d\n", digits[i]);
|
||||
}
|
||||
printf("To output it reversely: ");
|
||||
for (int i = 0; i < digit; i++) {
|
||||
printf("%d", digits[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user