draft
This commit is contained in:
10
programs/p41/info.json
Normal file
10
programs/p41/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "課題1",
|
||||
"description": "教科書の演習4ー1の解答",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p41.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p41/main
Executable file
BIN
programs/p41/main
Executable file
Binary file not shown.
24
programs/p41/main.c
Normal file
24
programs/p41/main.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int n;
|
||||
int retry = 1;
|
||||
|
||||
do {
|
||||
printf("Input integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
if (n > 0) {
|
||||
printf("%d is positive.\n", n);
|
||||
} else if (n < 0) {
|
||||
printf("%d is negative.\n", n);
|
||||
} else {
|
||||
printf("It is zero.\n");
|
||||
}
|
||||
|
||||
printf("Retry? [1/0]: ");
|
||||
scanf("%d", &retry);
|
||||
} while (retry == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
programs/p42/info.json
Normal file
10
programs/p42/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "課題2",
|
||||
"description": "教科書の演習4ー2の解答",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p42.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p42/main
Executable file
BIN
programs/p42/main
Executable file
Binary file not shown.
21
programs/p42/main.c
Normal file
21
programs/p42/main.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int a, b, i, ans;
|
||||
|
||||
printf("Input upper limit: ");
|
||||
(void)scanf("%d", &a);
|
||||
printf("Input lower limit: ");
|
||||
(void)scanf("%d", &b);
|
||||
|
||||
i = b;
|
||||
ans = 0;
|
||||
|
||||
do {
|
||||
ans += i++;
|
||||
} while (i <= a);
|
||||
|
||||
printf("Sum of all integer between %d and %d is %d.\n", b, a, ans);
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
programs/p43/info.json
Normal file
10
programs/p43/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "課題3",
|
||||
"description": "教科書の演習4ー3の解答",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p43.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p43/main
Executable file
BIN
programs/p43/main
Executable file
Binary file not shown.
19
programs/p43/main.c
Normal file
19
programs/p43/main.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int n;
|
||||
|
||||
printf("Input positive integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
while (n >= 0) {
|
||||
printf("%d ", n);
|
||||
n--;
|
||||
|
||||
if (n < 0) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
programs/p44/info.json
Normal file
10
programs/p44/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "課題4",
|
||||
"description": "教科書の演習4ー4の解答",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p44.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p44/main
Executable file
BIN
programs/p44/main
Executable file
Binary file not shown.
18
programs/p44/main.c
Normal file
18
programs/p44/main.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int n;
|
||||
|
||||
printf("Input positive integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
while (n > 0) {
|
||||
printf("%d ", n--);
|
||||
|
||||
if (n == 0) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user