Pythagorean triplet

question:

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^(2) + b^(2) = c^(2)
For example, 3^(2) + 4^(2) = 9 + 16 = 25 = 5^(2).
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

posted under , |

0 comments:

Newer Post Older Post Home

About Me

My photo
Hi everyone,myself Alagappan...electronic and communication engg. student... living in madurai... interested in everything... want to achieve something great in my lifetime...

Followers


Recent Comments