Uva 100 Solution

#include<stdio.h>
int anik(int a, int b)
{
    int x, count = 1,max = 0,temp;
    if(a>b)
    {
        temp = a;
        a = b;
        b = temp;
    }
    while(a<=b)
    {
        x = a;
        while(x != 1)
        {
            if(x%2 == 0)
            {
                x = x/2;
            }
            else
            {
                x = (3*x) + 1;
            }
            count++;
            if(x == 1)
            {
                break;
            }
        }
        if(count>max)
        {
            max = count;
        }
        count = 1;
        a++;
    }
    return max;
}
int main()
{
    int i,j,ans;
    while(scanf("%d %d", &i,&j) != EOF)
    {
        ans = anik(i,j);
        printf("%d %d %d\n", i,j,ans);
    }
    return 0;
}

Comments