-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW1.cpp
81 lines (52 loc) · 1.25 KB
/
HW1.cpp
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
//Muhammad Ghazi
//HW1 Question 1
#include <iostream>
using namespace std;
//The recursion function is here
int recursion(int a, int b)
{
if (b < 3)
{
cout << "Instance of recursion: " << b << endl << endl;
b++;
return recursion(a, b);
}
else if (b <= a)
{
int c = (b - 1) + (b - 2) + (b - 3);
cout << "For the " << b << " recursion, the number the function produces is: " << c << endl << endl;
b++;
return recursion(a, b);
}
else
{
return 0;
}
}
int main()
{
//Iteration function is here
int iteration;
cout << "Enter in a number greater than 2" << endl;
cin >> iteration;
for (int i = 0; i <= iteration; i++)
{
int value = 0;
//cout << "Instance of iteration: " << i << endl;
if (i > 2)
{
value = (i - 1) + (i - 2) + (i - 3);
cout << "For the " << i << " iteration, the number the function produces is: " << value << endl << endl;
}
else if (iteration < 2)
{
cout << "Oops, you entered a number less than 3..." << endl;
continue;
}
}
cout << "Now we have seen the iteration function, next is the recursion function" << endl;
int counter = 0;
recursion(iteration, counter);
system("pause");
return 0;
}