-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.c
81 lines (56 loc) · 1.69 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// 1. numbers ,opertions,
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void main(){
int n1 ,n2 , opt;
float res;
do{
printf("Enter the first number n1 : ");
scanf("%d" , &n1);
printf("Select an Operation in Calculation \n 1 Addition \t \t 2 Subtraction \n 3 Multipication \t \t 4 Division \n 5 Exit \n Make a choice : ");
scanf("%d" , &opt);
printf("Enter the second number n2 : ");
scanf("%d" , &n2);
switch(opt) {
case 1:
printf("You choose : %d \n" , opt);
printf("You choose Addition\n");
res = n1 + n2;
printf("\nThe Addition of n1 and n2 is : %.2f" , res);
break;
case 2:
printf("You choose : %d \n" , opt);
printf("You choose Subtraction\n");
res = n1 - n2;
printf("\nThe Subtraction of n1 and n2 is : %.2f" , res);
break;
case 3:
printf("You choose : %d \n" , opt);
printf("You choose Multipication\n");
res = n1 * n2;
printf("\nThe Multipication of n1 and n2 is : %.2f" , res);
break;
case 4:
printf("You choose : %d \n" , opt);
printf("You choose Division\n");
if (n2 == 0)
{
printf (" \n Divisor cannot be zero. Please enter another value ");
scanf ("%d", &n2);
}
res = n1 / n2;
printf ("\nDivision of two numbers is: %.2f", res);
break;
case 5:
printf("You choose : %d \n" , opt);
printf ("You choose: Exit");
exit(0);
break;
default:
printf(" Something is wrong!! ");
break;
}
printf (" \n \n ********************************************** \n ");
} while (opt != 5);
}