UVA 100 - The 3n + 1 problem

Problem PDF

Solution:

#include
int main()
{
    int n,m,i,k,j,c,s;
    while(scanf("%d %d",&n,&m)==2)
    {
        s=0;
        printf("%d %d ",n,m);
        if(n>m)
        {
            k=m;
            m=n;
            n=k;
        }
        for(i=n;i<=m;i++)
        {
            c=1;
            j=i;
            while(j>1)
            {
                if(j%2==0)
                j=j/2;
                else
                j=(3*j)+1;
                c++;
            }
            if(c>=s)
                s=c;
        }
        printf("%d\n",s);
    }
    return 0;
}

https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/100/100.cpp