1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
void swap( int& a, int& b ) { const int temp = a ; a = b ; b = temp ; }
void make_ascending( int& a, int& b ) { if( b < a ) swap(a,b) ; }
void make_ascending( int& a, int& b, int& c ) { make_ascending(a,b) ; make_ascending(b,c) ; make_ascending(a,b) ; }
bool is_side( int a ) { return a > 0 ; }
bool is_triangle( int a, int b, int c ) // a, b, c in ascending order
{ return is_side(a) && is_side(b) && is_side(c) && (a+b) > c ; }
enum type { isosceles, equilateral, right_angled, scalene_not_right_angled, not_a_triangle = -1 };
type triangle_type( int a, int b, int c )
{
make_ascending(a,b,c) ;
if( is_triangle(a,b,c) )
{
if( a==b ) return b==c ? equilateral : isosceles ;
else return ( a*a + b*b == c*c ) ? right_angled : scalene_not_right_angled ;
}
else return not_a_triangle ;
}
|