Salam to Muslims,
Hi there guys,
I need some help with this problem. I have written code and it does work as far as I can tell but one of the online judges does not accept it.
Please suggest any amendments to make the code better:
Thanks.Code:#include <iostream>
using namespace std;
int CycleLength(int x);
int main(){
while(1){
int unsigned i,j,k,l,max=0;
cin>>i>>j;
k=i;
l=j;
if ((i==0)&&(j==0)) break;
if(i==j){max=CycleLength(i);}
else
if(i>j){for(i;i>j;i--){
if (CycleLength(i)>max)
max=CycleLength(i);
}
}
{
for(i;i<j;i++){
if (CycleLength(i)>max)
max=CycleLength(i);
}
}
cout<<k<<" "<<l<<" "<<max<<endl;}
}
int CycleLength(int x){
int count=1;
while(x>1){
if (x%2==!0)
x=3*x+1;
else x=x/2;
count++;
}
return count;
}