Check if a right | C ++ program to implement the above approach ; Function to check if N is a perfect square number or not ; If N is a non positive integer ; Stores square root of N ; Check for perfect square ; If N is not a perfect square number ; Function to check if given two sides of a triangle forms a right - angled triangle ; If the value of ( A * A + B * B ) is a perfect square number ; Update checkTriangle ; If the value of ( A * A - B * B ) is a perfect square number ; Update checkTriangle ; If the value of ( B * B - A * A ) is a perfect square number ; Update checkTriangle ; Driver Code ; If the given two sides of a triangle forms a right - angled triangle ; Otherwise
#include <bits/stdc++.h> NEW_LINE using namespace std ; int checkPerfectSquare ( int N ) { if ( N <= 0 ) { return 0 ; } double sq = sqrt ( N ) ; if ( floor ( sq ) == ceil ( sq ) ) { return 1 ; } return 0 ; } bool checktwoSidesareRighTriangle ( int A , int B ) { bool checkTriangle = false ; if ( checkPerfectSquare ( A * A + B * B ) ) { checkTriangle = true ; } if ( checkPerfectSquare ( A * A - B * B ) ) { checkTriangle = true ; } if ( checkPerfectSquare ( B * B - A * A ) ) { checkTriangle = true ; } return checkTriangle ; } int main ( ) { int A = 3 , B = 4 ; if ( checktwoSidesareRighTriangle ( A , B ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }