progress
This commit is contained in:
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