| Input | Output | |
| Test Case 1 | 3 5 4 | yes |
| Test Case 2 | 5 8 2 | no |
| Test Case 3 | 5 12 13 | yes |
| Test Case 4 | 50 130 120 | yes |
| Test Case 5 | 120 130 50 | yes |
| Test Case 6 | 9999 9801 1980 | yes |
| Test Case 7 | 5 8 12 | no |
#include <stdio.h> int main() { int i, j, k; /* inputs */ int i_sq, j_sq, k_sq; /* squares of inputs */ scanf("%d",&i); scanf("%d",&j); scanf("%d",&k); /* compute the squares of inputs */ i_sq = i*i; j_sq = j*j; k_sq = k*k; /* check if some ordering of the inputs * form a Pythagorean triple */ if(i_sq+j_sq == k_sq || j_sq+k_sq == i_sq || i_sq+k_sq == j_sq){ printf("yes"); }else{ printf("no"); } } /*------------------------------------------- * Additional comments: * The only thing to note here is the way * the if condition was written. We do not * know in what order i,j,k satisfy the * condition we need. * So we have to check for the three * possibilities. * * Note that only the largest number can * be on the right hand side of the equation * a*a + b*b = c*c * You can use this observation for another * solution to the problem. However, in this * case,you have to find the maximum of the three * numbers. */
Labels: c programsum of squares of two numbers is equal to the square of the third, Pythagorean Triples