Saturday, May 21, 2011

834 - Continued Fractions


#include<stdio.h>
int main()
{
    register int a,b,c,k;
    //freopen("in.txt","r",stdin);

    while(scanf("%d%d",&a,&b)==2)
    {
        k=0;
        while(b)
        {
            switch(k)
            {
            case 0:
                printf("[%d",a/b);
                break;
            case 1:
                printf(";%d",a/b);
                break;
            default:
                printf(",%d",a/b);
                break;
            }
            c = b;
            b = a%b;
            a = c;
            k++;
        }
        printf("]\n");
    }
    return 0;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.