Pythagorean triplet
question:
A Pythagorean triplet is a set of three natural numbers, a b c, for which,
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
answer:
#include
#include
void main()
{
long int a,b,c,as,bs,cs;
clrscr();
for(a=1;a<1000;a++)
for(b=1;b<1000;b++)
for(c=1;c<1000;c++)
{
as=a*a;
bs=b*b;
cs=c*c;
if((as+bs)==cs)
{
if(a+b+c==1000)
printf("a=%ld,b=%ld,c=%ld\t as=%ld,bs=%ld,cs=%ld\tproduct=%ld\n",a,b,c,as,bs,cs,a*b*c);
}
}
printf("over\n");
getch();
}
answer:31875000
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
answer:
#include
#include
void main()
{
long int a,b,c,as,bs,cs;
clrscr();
for(a=1;a<1000;a++)
for(b=1;b<1000;b++)
for(c=1;c<1000;c++)
{
as=a*a;
bs=b*b;
cs=c*c;
if((as+bs)==cs)
{
if(a+b+c==1000)
printf("a=%ld,b=%ld,c=%ld\t as=%ld,bs=%ld,cs=%ld\tproduct=%ld\n",a,b,c,as,bs,cs,a*b*c);
}
}
printf("over\n");
getch();
}
answer:31875000
0 comments:
Post a Comment