-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalculator.c
More file actions
50 lines (40 loc) · 846 Bytes
/
Calculator.c
File metadata and controls
50 lines (40 loc) · 846 Bytes
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
48
49
50
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
int a, b;
float c;
char ch;
printf("Enter operator (+,-,*,/,%)\n");
scanf("%c", &ch);
printf("Enter values of a & b :\n");
scanf("%d%d", &a, &b);
switch (ch)
{
case '+':
c = (a + b);
printf("Addition is : %0.2f", c);
break;
case '-':
c = (a - b);
printf("Substraction is : %0.2f", c);
break;
case '*':
c = 1.0 * a * b;
printf("Multiplication is : %0.2f", c);
break;
case '/':
c = (a * 1.0) / b;
printf("Division is : %0.3f", c);
break;
case '%':
c = (a % b) * 1.0;
printf("Reminder is : %0.2f", c);
break;
default:
printf("invalid operator");
break;
}
return 0;
}