-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.c
More file actions
129 lines (110 loc) · 3.1 KB
/
calculator.c
File metadata and controls
129 lines (110 loc) · 3.1 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float sum(float, float);
float difference(float, float);
float product(float, float);
float quotient(float , float);
float float_remainder(int , int);
int power(int , int);
float squareRoot(float);
int main()
{
int choice;
float x, y , res = 0;
do
{
printf("Enter your choice:\n");
printf("1.Additon \n2.Subtraction \n3.Multiplication \n4.Divison \n5.Remainder \n6.Power \n7.SquareRoot \n8.Exit");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter two numbers :");
scanf("%f%f",&x,&y);
res = sum(x,y);
printf("sum of %f and %f is = %f",x,y,res);
break;
case 2:
printf("Enter two numbers:");
scanf("%f%f",&x,&y);
res = difference(x,y);
printf("differnce of %f and %f is = %f",x,y,res);
break;
case 3:
printf("Enter two numbers: ");
scanf("%f%f",&x,&y);
res = product(x,y);
printf("product of %f and %f is = %f",x,y,res);
break;
case 4:
printf("Enter dividend and divisor ");
scanf("%f%f",&x,&y);
res = quotient(x,y);
printf("quotient of %f and %f is = %f",x,y,res);
break;
case 5:
printf("Enter dividend and divisor:");
scanf("%d%d",&x,&y);
res = float_remainder(x,y);
printf("remainder when %d is divided by %d is = %f",x,y,res);
break;
case 6:
printf("Enter the number and power that number should be raised ");
scanf("%d%d",&x,&y);
res = power(x,y);
printf("%d raised %d times is = %d",x,y,res);
break;
case 7:
printf("Enter the number:");
scanf("%f",&x);
res = squareRoot(x);
printf("sqaure root of %f is = %f",x,res);
break;
case 8: exit(0);
default: printf("Enter choice between 1 to 8");
break;
}
}while (1);
return 0;
}
float sum(float a, float b)
{
return a+b;
}
float difference(float a, float b)
{
if(a > b)
return a-b;
else
return b-a;
}
float product(float a, float b)
{
return a*b;
}
float quotient(float a, float b)
{
if(b == 0)
printf("Division by zero is not possible:");
else
return a/b;
}
float float_remainder(int a, int b)
{
if( b == 0)
{
printf("not possible: ");
return -1;
}
else
return a%b;
}
int power(int a, int b)
{
return pow(a,b);
}
float squareRoot(float a)
{
return sqrt(a);
}