This commit is contained in:
2025-06-19 17:30:16 +09:00
parent 261688c4bc
commit 3a3c8f4675
27 changed files with 340 additions and 24 deletions

View File

@@ -1,10 +1,10 @@
{
"language": "",
"name": "",
"description": "",
"language": "C",
"name": "簡易電卓",
"description": "2つの実数を入力し、四則演算を指定し、小数点6桁で結果を表示する。0 divも考慮すること。",
"output": {
"type": "screenshot | text",
"content": ""
"type": "screenshot",
"content": "./assets/calc.png"
},
"note": ""
}

BIN
programs/calc/main Executable file

Binary file not shown.

View File

@@ -0,0 +1,48 @@
#include <stdio.h>
#define ADD 1
#define SUB 2
#define MUL 3
#define DIV 4
int main(void) {
double a, b;
int op;
printf("Input first number: ");
scanf("%lf", &a);
printf("Input second number: ");
scanf("%lf", &b);
printf("Select Operation:\n"
"[1]: Addition\n"
"[2]: Subtraction\n"
"[3]: Multiplication\n"
"[4]: Division\n"
"> ");
scanf("%d", &op);
switch (op) {
case ADD:
printf("ANS: %lf\n", a + b);
break;
case SUB:
printf("ANS: %lf\n", a - b);
break;
case MUL:
printf("ANS: %lf\n", a * b);
break;
case DIV:
if (b == 0.0) {
puts("Zero Division");
return 1;
}
printf("ANS: %lf\n", a / b);
break;
default:
puts("Undefined Operation");
return 1;
}
return 0;
}

View File

@@ -0,0 +1,8 @@
with open("./ifs.c", mode='w') as file:
num = 100000
file.write("int comp(int x) {\n if (x == 0) {\n return 0;\n } ")
for i in range(1,num-1):
s = f"else if (x == {i}) {{\n return {i};\n }} "
file.write(s)
file.write(f"else {{\n return {num-1};\n }}\n}}")
file.write(f"\n\nint main(void) {{\n for (int i = 0; i < {num}; i++) {{ \n comp(i);\n }}\n return 0;\n}}\n")

View File

@@ -0,0 +1,8 @@
with open("./switch-case.c", mode='w') as file:
num = 100000
file.write("int comp(int x) {\n switch (x) {\n")
for i in range(num):
s = f" case {i}: return {i};\n"
file.write(s)
file.write(" }\n}")
file.write(f"\n\nint main(void) {{\n for (int i = 0; i < {num}; i++) {{\n comp(i);\n }}\n return 0;\n}}\n")

Binary file not shown.

View File

@@ -1,10 +1,10 @@
{
"language": "",
"name": "",
"description": "",
"language": "C",
"name": "演習 3-12",
"description": "教科書のList 3-4をSwitch文で書き換えたプログラム。",
"output": {
"type": "screenshot | text",
"content": ""
"type": "screenshot",
"content": "./assets/p312.png"
},
"note": ""
}

BIN
programs/p312/main Executable file

Binary file not shown.

View File

@@ -0,0 +1,21 @@
#include <stdio.h>
int main(void) {
int n;
printf("Input Integer: ");
scanf("%d", &n);
switch (n % 2) {
case 0:
puts("The number is even.");
break;
case 1:
puts("The number is odd.");
break;
default:
puts("Unknown Error");
}
return 0;
}

View File

@@ -1,10 +1,10 @@
{
"language": "",
"name": "",
"description": "",
"language": "C",
"name": "演習 3-13",
"description": "教科書のList 3-18 をSwitch文で書き換えたプログラム。",
"output": {
"type": "screenshot | text",
"content": ""
"type": "screenshot",
"content": "./assets/p313.png"
},
"note": ""
}

BIN
programs/p313/main Executable file

Binary file not shown.

View File

@@ -0,0 +1,35 @@
#include <stdio.h>
int main(void) {
int month;
printf("Input month: ");
scanf("%d", &month);
switch (month) {
case 12:
case 1:
case 2:
puts("It is winter.");
break;
case 3:
case 4:
case 5:
puts("It is spring.");
break;
case 6:
case 7:
case 8:
puts("It is summer.");
break;
case 9:
case 10:
case 11:
puts("It is autumn.");
break;
default:
puts("Unknown month.");
}
return 0;
}