Friday, 3 July 2015

Pythagorean Triples

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

/*CODE*/

#include<stdio.h>
int main()
{
int a,b,c,max;
scanf("%d %d %d",&a,&b,&c);
max=a;
if(max<b)
max=b;
if(max<c)
max=c;
if(max==b)
{
if(a*a+c*c==b*b)
{
printf("yes");
return 0;
}
}
if(max==c)
{
if(a*a+b*b==c*c)
{
printf("yes");
return 0;
}
}
if(max==a)
{
if(b*b+c*c==a*a)
{
printf("yes");
return 0;
}
}
printf("no");
return 0;
}

No comments:

Post a Comment