draft
This commit is contained in:
10
programs/p412/info.json
Normal file
10
programs/p412/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "演習 4-12",
|
||||
"description": "入力した正の整数値の桁数を表示するプログラム。",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p412.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p412/main
Executable file
BIN
programs/p412/main
Executable file
Binary file not shown.
24
programs/p412/main.c
Normal file
24
programs/p412/main.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int n;
|
||||
|
||||
do {
|
||||
printf("Input positive integer: ");
|
||||
scanf("%d", &n);
|
||||
if (n <= 0) {
|
||||
puts("\aPlease input non-negative, non-zero integer.");
|
||||
}
|
||||
} while (n <= 0);
|
||||
|
||||
int d = 0;
|
||||
int x = n;
|
||||
while (x > 0) {
|
||||
x /= 10;
|
||||
d++;
|
||||
}
|
||||
|
||||
printf("%d is %d digit number.\n", n, d);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user