제 소스는 이렇습니다~!
#include <stdio.h>
int main(void)
{
int min, max, cycle, maxcycle=0, n=0, i;
printf("Input : ");
scanf("%d%d",&min,&max);
for(i=min; i<=max; i++)
{
cycle=1;
n=i;
while(1)
{
if(n == 1)
{
if(cycle > maxcycle)
maxcycle = cycle;
break;
}
if(n%2 && n != 1)
{
n*=3; n++;
cycle++;
}
else if(n%2 == 0)
{
n/=2;
cycle++;
}
}
}
printf("Output : %d\n", maxcycle);
return 0;
} '진주의 배설물 > 알고리즘 소스' 카테고리의 다른 글
[C언어] 배열과 함수만을 이용한 Queue (0) | 2012.02.03 |
---|---|
[C언어] 2차원 배열 - 달팽이 알고리즘 - (0) | 2012.02.03 |