-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmathcalculation.cpp
More file actions
105 lines (102 loc) · 2.25 KB
/
mathcalculation.cpp
File metadata and controls
105 lines (102 loc) · 2.25 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
#include <iostream>
using namespace std;
int main()
{
int option;
cout << "Press [1] - To display specific tables from starting and ending values given by user." << endl;
cout << "Press [2] - To display first 10 non-negaives whole numbers in desending order." << endl;
cout << "Press [3] - To calculate factorial of a number." << endl;
cout << "Press [4] - To calculate the sum of first 10 odd numbers." << endl;
cout << "Press [5] - To display whether the input number is prime or not." << endl;
cout << "Please enter your option here.... ";
cin >> option;
switch (option)
{
case 1:
{
int val, start, end, prod;
cout << "Enter the value to make a table... ";
cin >> val;
cout << "Enter the starting value... ";
cin >> start;
cout << "Enter the ending value... ";
cin >> end;
cout << endl;
for (val; start <= end; start++)
{
prod = val*start;
cout << val << " x " << start << " = " << prod << endl;
}
break;
}
case 2:
{
int b = 9;
for (int a = 1; a <= 10; a++)
{
cout << a << " whole number is " << b << endl;
b--;
}
break;
}
case 3:
{
int num, n = 1;
double fac = 1;
cout << "Enter the number you want to calculate the factorial of...";
cin >> n;
for (num = 1; num <= n; ++num)
{
fac *= num;
}
cout << fac << endl;
break;
}
case 4:
{
int a, sum = 0;
for (a = 1; a <= 20; a += 2)
{
sum += a;
cout << a << " + ";
}
cout << " = " << sum << endl;
break;
}
case 5:
{
int num, i, m = 0, pflag = 0;
cout << "Enter the number here... ";
cin >> num;
if (num == 1 || num == 2) {
cout << num << " is a prime number. " << endl;
}
else if (num <= 0)
{
cout << num << " is not a prime number " << endl;
}
else
m = num / 2;
{
for (i = 2; i <= m; i++)
{
if (num % i == 0) {
cout << num << " not a prime number. " << endl;
pflag = 1;
break;
}
if (pflag == 0) {
cout << num << " is a prime number. " << endl;
break;
}
}
}
break;
}
default:
{
cout << "Please enter a valid option." << endl;
}
}
return 0;
}