照我的试试,我已经和实例的一样结果了
#include <stdio.h>
#include <stdlib.h>
int Count(int n);
int main()
{
int i, j, temp;
int p, max, sum, maxnumber;
while(scanf("%d%d",&i,&j) == 2 && (i != 0 && j != 0))
{
if(i > j)//i比j大,交换一下
{
temp = i;
i = j;
j = temp;
}
sum = 0;
max = 0;
for(p = i; p <= j; p++)
{
sum = Count(p);
if(sum > max)
{
max = sum;
maxnumber = p;
}
}
printf("Between %d and %d, %d generates the longest sequence of %d values.\n", i, j, maxnumber, max);
}
return 0;
}
int Count(int n)
{
int i;
i = 0;
while(n != 1)
{
if(n%2 == 0)
n/=2;
else
n = n*3 + 1;
i++;
}
return i;
}
#include <stdio.h>
#include <stdlib.h>
int Count(int n);
int main()
{
int i, j, temp;
int p, max, sum, maxnumber;
while(scanf("%d%d",&i,&j) == 2 && (i != 0 && j != 0))
{
if(i > j)//i比j大,交换一下
{
temp = i;
i = j;
j = temp;
}
sum = 0;
max = 0;
for(p = i; p <= j; p++)
{
sum = Count(p);
if(sum > max)
{
max = sum;
maxnumber = p;
}
}
printf("Between %d and %d, %d generates the longest sequence of %d values.\n", i, j, maxnumber, max);
}
return 0;
}
int Count(int n)
{
int i;
i = 0;
while(n != 1)
{
if(n%2 == 0)
n/=2;
else
n = n*3 + 1;
i++;
}
return i;
}