done
This commit is contained in:
10
programs/p413/info.json
Normal file
10
programs/p413/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "演習 4-13",
|
||||
"description": "1から$n$までの総和を求めるプログラム。",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p413.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p413/main
Executable file
BIN
programs/p413/main
Executable file
Binary file not shown.
23
programs/p413/main.c
Normal file
23
programs/p413/main.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int n;
|
||||
int sum = 0;
|
||||
|
||||
numInput:
|
||||
printf("Input integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
if (n < 1) {
|
||||
puts("Error: Please type in non-zero positive integer.");
|
||||
goto numInput;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
sum += i;
|
||||
}
|
||||
|
||||
printf("ANS: %d", sum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
programs/p414/info.json
Normal file
10
programs/p414/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "演習 4-14",
|
||||
"description": "1,2,3...8,9,0を入力した整数値個表示するプログラム。",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p414.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p414/main
Executable file
BIN
programs/p414/main
Executable file
Binary file not shown.
22
programs/p414/main.c
Normal file
22
programs/p414/main.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int n;
|
||||
|
||||
numInput:
|
||||
printf("Input positive integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
if (n < 0) {
|
||||
puts("Please input positive integer.");
|
||||
goto numInput;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
printf("%d", i % 10);
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
programs/p418/info.json
Normal file
10
programs/p418/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "演習 4-18",
|
||||
"description": "入力した整数値の個数分アスタリスクを各行に5個ずつ表示するプログラム。",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p418.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p418/main
Executable file
BIN
programs/p418/main
Executable file
Binary file not shown.
25
programs/p418/main.c
Normal file
25
programs/p418/main.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define CHARSPERLINE 5
|
||||
|
||||
int main(void) {
|
||||
int n;
|
||||
|
||||
numInput:
|
||||
printf("Input integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
if (n < 1) {
|
||||
puts("Please input non-zero positive integer.");
|
||||
goto numInput;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
putchar('*');
|
||||
if (i % CHARSPERLINE == 0) {
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
programs/p419/info.json
Normal file
10
programs/p419/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "演習 4-19",
|
||||
"description": "入力した整数値の全約数とその個数を表示するプログラム。",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p419.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p419/main
Executable file
BIN
programs/p419/main
Executable file
Binary file not shown.
26
programs/p419/main.c
Normal file
26
programs/p419/main.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int n;
|
||||
int factors = 0;
|
||||
|
||||
numInput:
|
||||
printf("Input integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
if (n < 1) {
|
||||
puts("Please input positive integer.");
|
||||
goto numInput;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (n % i == 0) {
|
||||
printf("%d\n", i);
|
||||
factors++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Number of factors: %d\n", factors);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user