-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
41 lines (35 loc) · 872 Bytes
/
main.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
#include <iostream>
#include <string>
int main()
{
int num;
unsigned int iterations = 0;
long long maxNumber = 0;
std::cout << "Only natural number > 0" << '\n';
std::cout << "Please enter number: ";
std::cin >> num;
std::cin.ignore(1000, '\n'); //Delete Keyboard buffer
std::cout << '\n';
while(num > 1) //2.
{
++iterations; //Count iterations
//1.
if (num % 2 == 0) //Number is prime
num /= 2;
else //Number is not prime
num = 3 * num + 1;
std::cout << num << '\n';
if(maxNumber < num) //Check for new maxNumber
{
maxNumber = num;
std::cout << "New maximum. Continue with ENTER";
std::string tmp;
std::getline(std::cin, tmp);
}
}
std::cout << '\n';
std::cout << iterations << " Iterations. Maximum Number = " << maxNumber << '\n' << '\n';
std::cout << "Press Enter to continue . . . ";
std::cin.get();
return 0;
}