fork download
  1. #include <iostream>
  2. #include <array>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. bool is_right_triangle(array<int, 3> sides) {
  7. decltype(sides) squares;
  8.  
  9. auto square = [](int x){
  10. return x*x;
  11. };
  12.  
  13. sort(begin(sides), end(sides));
  14. transform(begin(sides), end(sides), begin(squares), square);
  15.  
  16. return squares[0]+squares[1] == squares[2];
  17. }
  18.  
  19. int main() {
  20. cout << boolalpha;
  21.  
  22. cout
  23. << is_right_triangle({3, 4, 5}) << endl
  24. << is_right_triangle({6, 10, 8}) << endl
  25. << is_right_triangle({75, 21, 72}) << endl
  26. << endl;
  27.  
  28. cout
  29. << is_right_triangle({13, 4, 5}) << endl
  30. << is_right_triangle({16, 10, 8}) << endl
  31. << is_right_triangle({175, 21, 72}) << endl
  32. << endl;
  33. return 0;
  34. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
true
true
true

false
false
false