This commit is contained in:
2025-06-26 15:18:33 +09:00
parent e027e09906
commit 451aaee7ce
33 changed files with 366 additions and 106 deletions

10
programs/a5/info.json Normal file
View File

@@ -0,0 +1,10 @@
{
"language": "C",
"name": "課題5",
"description": "第10回の課題「簡易電卓」を繰り返し計算できるように変更したプログラム。",
"output": {
"type": "screenshot",
"content": "./assets/a5.png"
},
"note": ""
}

BIN
programs/a5/main Executable file

Binary file not shown.

54
programs/a5/main.c Normal file
View File

@@ -0,0 +1,54 @@
#include <stdio.h>
#define ADD 1
#define SUB 2
#define MUL 3
#define DIV 4
int main(void) {
double a, b;
int op;
int retry = 1;
do {
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;
}
printf("Retry? [1/0]: ");
scanf("%d", &retry);
} while (retry == 1);
return 0;
}