Algorithm Analysis
A triangle with sides , , is right-angled if one of the conditions is met: or or .
Algorithm Implementation
We read the lengths of the triangle sides.
scanf("%d %d %d", &a, &b, &c);
We check if the triangle is right-angled. Depending on this, we output the answer.
if ((a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)) puts("YES"); else puts("NO");
Java Implementation
import java.util.*; public class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in); int a = con.nextInt(); int b = con.nextInt(); int c = con.nextInt(); if ((a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)) System.out.println("YES"); else System.out.println("NO"); con.close(); } }
Python Implementation
We read the lengths of the triangle sides.
a, b, c = map(int, input().split())
We check if the triangle is right-angled. Depending on this, we output the answer.
if a * a + b * b == c * c or a * a + c * c == b * b or b * b + c * c == a * a: print("YES") else: print("NO")