This repository was archived by the owner on Sep 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathCalculator.cpp
More file actions
161 lines (151 loc) · 3.29 KB
/
Calculator.cpp
File metadata and controls
161 lines (151 loc) · 3.29 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include<bits/stdc++.h>
using namespace std;
void add()
{
int n, sum = 0, i, number;
cout << "How many numbers you want to add: ";
cin >> n;
cout << "Please enter the number one by one: \n";
for (i = 1; i <= n; i++)
{
cin >> number;
sum = sum + number;
}
cout << "\n Sum of the numbers = " << sum;
}
void sub()
{
int num1, num2, z;
cout << " \n Enter the First number = ";
cin >> num1;
cout << "\n Enter the Second number = ";
cin >> num2;
z = num1 - num2;
cout << "\n Subtraction of the number = " << z;
}
void multi()
{
int num1, num2, mul;
cout << " \n Enter the First number = ";
cin >> num1;
cout << "\n Enter the Second number = ";
cin >> num2;
mul = num1 * num2;
cout << "\n Multiplication of two numbers = " << mul;
}
void division()
{
int num1, num2, div = 0;
cout << " \n Enter the First number = ";
cin >> num1;
cout << "\n Enter the Second number = ";
cin >> num2;
while (num2 == 0)
{
cout << "\n Divisor canot be zero"
"\n Please enter the divisor once again: ";
cin >> num2;
}
div = num1 / num2;
cout << "\n Division of two numbers = " << div;
}
void sqr()
{
int num1;
float sq;
cout << " \n Enter a number to find the Square: ";
cin >> num1;
sq = num1 * num1;
cout << " \n Square of " << num1 << " is : " << sq;
}
void srt()
{
float q;
int num1;
cout << "\n Enter the number to find the Square Root:";
cin >> num1;
q = sqrt(num1);
cout << " \n Square Root of " << num1 << " is : " << q;
}
void mode()
{
int num1, num2, remi;
cout << " \n Enter the First number = ";
cin >> num1;
cout << "\n Enter the Second number = ";
cin >> num2;
remi=num1%num2;
cout << "\n Remainder of two numbers = " << remi;
}
void prime()
{
int num, i, chk=0;
cout<<"Enter a Number: ";
cin>>num;
for(i=2; i<num; i++)
{
if(num%i==0)
{
chk++;
break;
}
}
if(chk==0)
cout<<"\nIt is a Prime Number";
else
cout<<"\nIt is not a Prime Number";
}
int main()
{
int opr;
do
{
cout << "Select any operation from the C++ Calculator"
"\n1 = Addition"
"\n2 = Subtraction"
"\n3 = Multiplication"
"\n4 = Division"
"\n5 = Square"
"\n6 = Square Root"
"\n7 = Modulo"
"\n8 = Prime"
"\n9 = Exit"
"\n \n Make a choice: ";
cin >> opr;
switch (opr)
{
case 1:
add();
break;
case 2:
sub();
break;
case 3:
multi();
break;
case 4:
division();
break;
case 5:
sqr();
break;
case 6:
srt();
break;
case 7:
mode();
break;
case 8:
prime();
break;
case 9:
exit(0);
break;
default:
cout << "Something is wrong..!!";
break;
}
cout << " \n------------------------------\n";
} while (opr != 7);
return 0;
}