cpythagorean

How to check if 3 numbers are a Pythagorean triple?


How we could get three numbers without ordering and then check if they form a Pythagorean triple or not?

So, pythagorean(3, 4, 5) or pythagorean(5, 3, 4) will print/return true, while pythagorean(4, 3, 6) will print/return false.


Solution

  • You can use this algotrithm :

      #include<stdio.h>
      int main(){
    long long int a, b, c ;
    scanf("%llu %llu %llu", &a, &b, &c);
    
    if (a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b)
    {
        printf("YES");
    }
    
    else
        printf("NO");
       return 0;
       }