progress
This commit is contained in:
10
programs/a5/info.json
Normal file
10
programs/a5/info.json
Normal 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
BIN
programs/a5/main
Executable file
Binary file not shown.
54
programs/a5/main.c
Normal file
54
programs/a5/main.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user