diff options
author | zedarider <ymherklotz@gmail.com> | 2016-02-26 21:15:09 +0000 |
---|---|---|
committer | zedarider <ymherklotz@gmail.com> | 2016-02-26 21:15:09 +0000 |
commit | f7a1296d353dea1f98b47d4baef87426ceadf6b5 (patch) | |
tree | c4fc565b3e2f672647033d639601f695782f1562 /C++/Collatz.cpp | |
parent | c2d76b36f9f2ef70de599add53c08a38af3d1760 (diff) | |
download | imperial_2015-f7a1296d353dea1f98b47d4baef87426ceadf6b5.tar.gz imperial_2015-f7a1296d353dea1f98b47d4baef87426ceadf6b5.zip |
Organising into folders
Diffstat (limited to 'C++/Collatz.cpp')
-rw-r--r-- | C++/Collatz.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/C++/Collatz.cpp b/C++/Collatz.cpp new file mode 100644 index 0000000..5263710 --- /dev/null +++ b/C++/Collatz.cpp @@ -0,0 +1,34 @@ +#include <iostream> +#include <cmath> + +using namespace std; + +int main() { + int usrNum, usrNum1, usrNum2; + int count; + + cout << "Please Enter a range: "; + cin >> usrNum1 >> usrNum2; + + cout << "\nnumber\tsteps\n"; +// cout << usrNum1 << "\t" << usrNum2 << endl; + for(usrNum=usrNum1; usrNum<=usrNum2; usrNum++) { + count = 0; + int initNum = usrNum; + while(initNum > 1) { + if(initNum % 2 == 0) { + initNum = initNum / 2; + } + else { + initNum = initNum*3 + 1; + } + + count ++; + } + cout << usrNum << "\t" << count << "\t"; + for(int x = 0; x < count; x++) { + cout << "*"; + } + cout << endl; + } +}
\ No newline at end of file |