Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 5 June 2016

PROBLEM 20:

Ramanujan Number is the smallest number expressible as the sum of two cubes in two different ways. The two different ways are these:

1729 = 13 + 123 = 93 + 103

The second such number is 23 + 163 = 93 + 153 = 4104. Sequences of such numbers are called Taxicab numbers. Write a C program that print first n taxicab numbers (provided n > 0).


CODE:

#include<stdio.h>
main()
{
    int n,a,b,c,d,a3,b3,c3,d3;
    printf("Enter num");
    scanf("%d",&n);
    for(a=1;a<=n;a++)
    {
        a3=a*a*a;
        if(a3>n)
        break;
        for(b=a;b<=n;b++)
        {
            b3=b*b*b;
            if(a3+b3>n)
            break;
            for(c=a+1;c<=n;c++)
            {
                c3=c*c*c;
                if(c3>a3+b3)
                break;
                for(d=c;d<=n;d++)
                {
                    d3=d*d*d;
                    if(c3+d3>a3+b3)
                    break;
                    if(c3+d3==a3+b3)
                    {
                        printf("%d=%d^3+%d^3=%d^3+%d^3\n",(a3+b3),a,b,c,d);
                    }
        }
        }
        }
    }
    return 0;

}

Program Output:










For more problems click here

No comments:

Post a Comment