-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.c
53 lines (47 loc) · 1.55 KB
/
calculator.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
48
49
50
51
52
53
#include<stdio.h>
int main()
{
int var,a,b,c,ans;
do
{
printf("----------This is a calculator----------\n");
printf(" * For addition, press 1\n");
printf(" * For subtraction, press 2\n");
printf(" * For multiplication, press 3\n");
printf(" * For division, press 4\n");
printf(" * Press any other key to exit\n");
scanf("%d",&var);
switch(var)
{
case 1:
printf("Enter the two numbers to add\n");
scanf("%d\n%d",&a,&b);
c=a+b;
printf(" %d + %d = %d \n",a,b,c);
break;
case 2:
printf("Enter the two numbers to subtract(in order)\n");
scanf("%d\n%d",&a,&b);
c=a-b;
printf(" %d - %d = %d \n",a,b,c);
break;
case 3:
printf("Enter the two numbers to multiply\n");
scanf("%d\n%d",&a,&b);
c=a*b;
printf(" %d * %d = %d \n",a,b,c);
break;
case 4:
printf("Enter the two numbers to divide\n");
scanf("%d\n%d",&a,&b);
c=a/b;
printf(" %d / %d = %d \n",a,b,c);
break;
default:
break;
}
printf("Do you wish to calculate more? (Press 10 if yes): ");
scanf("%d",&ans);
}while(ans==10);
printf("Calculator turning off!\n");
}