int getCycleLen(int n){//counts the number of iterations before n=1
int cycle_len=0;
while(n!=1){
if(n%2==0) n/=2; else n=3*n+1;
cycle_len++;
}
return cycle_len;
}
int main(){
int i,j,n;
int max_len=0,len;
i = 1; j = 1000000;//j = a million
for(n=i;n<=j;n++){
printf("%d ",n);
len = getCycleLen(n);
if(len > max_len)
max_len=len;
}
printf("%d %d %d\n",i,j,max_len);
}
I am using Ubuntu 16.04 and compiling using gcc 5.4. For some reason the program hangs when n of the for loop is 113299. Any suggestions as to why this happens?