forked from nishitpanchal395/projecthactoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator with C
34 lines (31 loc) · 864 Bytes
/
Calculator with 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
//Calculator using C
#include <stdio.h>
int main() {
char op;
double first, second;
printf("Enter an operator (+, -, *, /,%): ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%lf %lf", &first, &second);
switch (op) {
case '+':
printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
break;
case '%':
printf("%.1lf / %.1lf = %.1lf", first, second, first % second);
break;
// operator doesn't match any case constant
default:
printf("Error! Please enter correct operator");
}
return 0;
}