-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalc_basic.c
47 lines (44 loc) · 1.34 KB
/
Calc_basic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
int main() {
char op = 'n';
int num1, num2;
float quotient;
signed int answer;
printf("Welcome heres a Simple Calculator :-\n");
printf("Enter first number : ");
scanf("%d", &num1);
printf("Enter second number : ");
scanf("%d", &num2);
printf("Which operation will you like to perform ? (choose by entering the respective symbol)\n");
printf("+ | Addition\n- | Subtraction\n* | Multiplication\n/ | Division\n%% | Modulus division (Remainder)\n\\ | Integer Division (Quotient)\n");
scanf("%s",&op);
switch (op) {
case '+':
answer = num1 + num2;
printf("Sum : %d", answer);
break;
case '-':
answer = num1 - num2;
printf("Difference : %d", answer);
break;
case '*':
answer = num1 * num2;
printf("Product : %d", answer);
break;
case '/':
quotient = num1 / num2;
printf("Quotient : %f", quotient);
break;
case '%':
answer = num1 % num2;
printf("Remainder : %d", answer);
break;
case '\\':
answer = num1 / num2;
printf("Integer Quotient : %d", answer);
break;
default:
printf("Invalid option.");
}
return 0;
}