diff options
author | zedarider <ymherklotz@gmail.com> | 2016-02-18 11:37:45 +0000 |
---|---|---|
committer | zedarider <ymherklotz@gmail.com> | 2016-02-18 11:37:45 +0000 |
commit | af98ee7ff28cff97f5f29a5d9e65f9153531b0ee (patch) | |
tree | 86bfc53a0bc04512ac2936ee067a2b43e901e688 /Collatz.cpp | |
download | imperial_2015-af98ee7ff28cff97f5f29a5d9e65f9153531b0ee.tar.gz imperial_2015-af98ee7ff28cff97f5f29a5d9e65f9153531b0ee.zip |
Imperial C++ Directory
These are all the projects I’ve been working on at university.
Diffstat (limited to 'Collatz.cpp')
-rw-r--r-- | Collatz.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Collatz.cpp b/Collatz.cpp new file mode 100644 index 0000000..5263710 --- /dev/null +++ b/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 |