Read post
Why Runtime Error?
[ Topic ] 2013-05-23 13:08:28 qyq79
#include<stdio.h>
long cycle(long n)
{
long i=1;
while(n!=1){
if(n%2==0){
n=n/2;
i++;
}
else{
n=n*3+1;
i++;
}
}
return i;
}
int main()
{
long i,j,s,max,temp;
while((scanf("%ld %ld",&i,&j))!=EOF){
printf("%ld %ld ",i,j);
if(i>j){
temp=i;
i=j;
j=temp;
}
for(max=0;i<=j;i++){
s=cycle(i);
if(s>max) max=s;
}
printf("%ld\n",max);
}
}
Reply
|