forked from akn714/1st-yr-c-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.c
36 lines (30 loc) · 948 Bytes
/
11.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
// Task : WAP that takes two operands and one operator from the user, perform the operation, and prints the result by using Switch statement
#include <stdio.h>
int main() {
int n, m;
char optr;
// inputting 2 numbers and and operator
scanf("%d %c %d", &n, &optr, &m);
// performing operation on the bases or operator (optr)
switch(optr){
case '+':
printf("%d %c %d = %d\n", n, optr, m, n+m);
break;
case '-':
printf("%d %c %d = %d\n", n, optr, m, n-m);
break;
case '*':
printf("%d %c %d = %d\n", n, optr, m, n*m);
break;
case '/':
printf("%d %c %d = %.2f\n", n, optr, m, (float) n/m);
break;
case '%':
printf("%d %c %d = %d\n", n, optr, m, n%m);
break;
default:
printf(" invalid operator\n");
break;
}
return 0;
}