Find other two sides and angles of a right angle triangle | C ++ program to print all sides and angles of right angle triangle given one side ; Function to find angle A Angle in front of side a ; applied cosine rule ; convert into degrees ; Function to find angle B Angle in front of side b ; applied cosine rule ; convert into degrees and return ; Function to print all angles of the right angled triangle ; for calculate angle A ; for calculate angle B ; Function to find other two sides of the right angled triangle ; if n is odd ; case of n = 1 handled separately ; case of n = 2 handled separately ; Print angles of the triangle ; Driver Program
#include <bits/stdc++.h> NEW_LINE #include <cmath> NEW_LINE using namespace std ; #define PI  3.1415926535 NEW_LINE double findAnglesA ( double a , double b , double c ) { double A = acos ( ( b * b + c * c - a * a ) / ( 2 * b * c ) ) ; return A * 180 / PI ; } double findAnglesB ( double a , double b , double c ) { double B = acos ( ( a * a + c * c - b * b ) / ( 2 * a * c ) ) ; return B * 180 / PI ; } void printAngles ( int a , int b , int c ) { double x = ( double ) a ; double y = ( double ) b ; double z = ( double ) c ; double A = findAnglesA ( x , y , z ) ; double B = findAnglesB ( x , y , z ) ; cout << " Angles ▁ are ▁ A ▁ = ▁ " << A << " , ▁ B ▁ = ▁ " << B << " , ▁ C ▁ = ▁ " << 90 << endl ; } void printOtherSides ( int n ) { int b , c ; if ( n & 1 ) { if ( n == 1 ) cout << -1 << endl ; else { b = ( n * n - 1 ) / 2 ; c = ( n * n + 1 ) / 2 ; cout << " Side ▁ b ▁ = ▁ " << b << " , ▁ Side ▁ c ▁ = ▁ " << c << endl ; } } else { if ( n == 2 ) cout << -1 << endl ; else { b = n * n / 4 - 1 ; c = n * n / 4 + 1 ; cout << " Side ▁ b ▁ = ▁ " << b << " , ▁ Side ▁ c ▁ = ▁ " << c << endl ; } } printAngles ( n , b , c ) ; } int main ( ) { int a = 12 ; printOtherSides ( a ) ; return 0 ; }