draft
This commit is contained in:
@@ -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
BIN
programs/calc/main
Executable file
Binary file not shown.
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user