Sunday 7 September 2014

Pythagorean Triples

Level: Easy

Three numbers form a Pythagorean triple if the sum of squares of two numbers is equal to the square of the third. 

 For example, 3, 5 and 4 form a Pythagorean triple, since 3*3 + 4*4 = 25 = 5*5 

You are given three integers, a, b, and c. They need not be given in increasing order. If they form a Pythagorean triple, then print "yes", otherwise, print "no". Please note that the output message is in small letters. 

Sample Input
3
5
4

Sample Output
yes



Program----


#include<stdio.h>

int main()
{int a,b,c,d,e,f;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);


if(a>b)
   {
    if(a>c)
   { d=a;e=b;f=c;}
   else
   {d=c;e=b;f=c;}
   
   }
   
   else
   {
   if(b>c)
   {d=b;e=a;f=c;}
   
   else
   {d=c;e=a;f=c;}
   }
   if(d*d==(e*e+f*f))
   printf("yes");
   else
   printf("no");
   
   return 0;
   }

No comments:

Post a Comment