Minimum and maximum possible length of the third side of a triangle | C ++ implementation of the approach ; Function to find the minimum and the maximum possible length of the third side of the given triangle ; Not a valid triangle ; Not a valid triangle ; Driver code
#include <iostream> NEW_LINE using namespace std ; void find_length ( int s1 , int s2 ) { if ( s1 <= 0 s2 <= 0 ) { cout << -1 ; return ; } int max_length = s1 + s2 - 1 ; int min_length = max ( s1 , s2 ) - min ( s1 , s2 ) + 1 ; if ( min_length > max_length ) { cout << -1 ; return ; } cout << " Max ▁ = ▁ " << max_length << endl ; cout << " Min ▁ = ▁ " << min_length ; } int main ( ) { int s1 = 8 , s2 = 5 ; find_length ( s1 , s2 ) ; return 0 ; }