cool stuff there itsme
here is my code anywho ..... waiting the 3rd contest
Code:
#include <iostream>
using namespace std;
int cycles(int i);
int main()
{
int i=0,j=0,current_cycles=0,max_cycles=0;
cout<<"Please enter 0 for both ranges to exit program\n\n";
while(true)
{
cout<<"Enter start and end range ( ex 1 10): ";
cin >>i>>j;
if(i ==0 && j == 0 )break; //break from loop.
while(i <=j )
{
current_cycles = cycles(i++);
if(current_cycles >= max_cycles)max_cycles = current_cycles;
}
cout<<"Maximum cycles within this range: "<<max_cycles<<"\n\n";
max_cycles=0;
}
return 0;
}
int cycles(int i)
{
if(i == 1)return 1; //if 1 return 1
if(i%2 == 0) return 1 + cycles(i/2); //do this if even
else return 1 + cycles((3*i)+1); //do this if odd
}