Find other two sides of a right angle triangle | C ++ program to print other two sides of right angle triangle given one side ; Finds two sides of a right angle triangle if it exist . ; if n is odd ; case of n = 1 handled separately ; case of n = 2 handled separately ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printOtherSides ( int n ) { if ( n & 1 ) { if ( n == 1 ) cout << -1 << endl ; else { int b = ( n * n - 1 ) / 2 ; int c = ( n * n + 1 ) / 2 ; cout << " b ▁ = ▁ " << b << " , ▁ c ▁ = ▁ " << c << endl ; } } else { if ( n == 2 ) cout << -1 << endl ; else { int b = n * n / 4 - 1 ; int c = n * n / 4 + 1 ; cout << " b ▁ = ▁ " << b << " , ▁ c ▁ = ▁ " << c << endl ; } } } int main ( ) { int a = 3 ; printOtherSides ( a ) ; return 0 ; }