The first triangle type can be determined. The two floating point data cannot be directly determined to be equal. For convenience of input, the precision set by yourself is relatively low, 10 ^ (-3)Copy codeThe Code is as follows:
# Include <stdio. h>
# Include <stdlib. h>
# Define EPSINON 1e-3
# Define ABS (a)> 0 )? (A) :(-))//? : Nested expressions are not supported.
# Define ZERO (x)>-EPSINON & (x) <EPSINON)
# Define MAX (a, B) (a)> (B ))? (A) (B ))
# Define MIN (a, B) (a) <(B ))? (A) (B ))
Float a, B, c;
Float max, mid, min;
Char input_err_flag = 0;
Char judge_err_flag = 0;
Int equal (float a, float B)
{
Float tmp;
Tmp = a-B;
Tmp = ZERO (ABS (tmp ));
Return tmp;
}
Void input (void)
{
A = B = c = 0;
Printf ("input three edge values :");
Scanf ("% f", & a, & B, & c );
If (! (A> 0) |! (B> 0) |! (C> 0 ))
{
Input_err_flag = 1;
}
}
Void sort (void)
{
Max = MAX (a, B), c );
Min = MIN (a, B), c );
If (MAX (a, B) <c)
Mid = MAX (a, B );
Else
Mid = MAX (MIN (a, B), c );
}
Void judge (void)
{
Float max_square, mid_square, min_square, tmp;
If (max> = (mid + min ))
{
Judge_err_flag = 1;
}
Else
{
Max_square = max * max;
Mid_square = mid * mid;
Min_square = min * min;
Tmp = mid_square + min_square;
If (equal (mid, min) | equal (max, mid ))
{
If (equal (mid, min ))
{
If (mid = max)
Puts ("equi triangle. ");
Else if (equal (max_square, tmp ))
Puts ("isosceles right triangle. ");
Else if (max_square <tmp)
Puts ("isosceles acute triangle. ");
Else
Puts ("isosceles blunt triangle. ");
}
Else
{
If (equal (min, mid ))
Puts ("equi triangle. ");
Else
Puts ("isosceles acute triangle. ");
}
}
Else if (equal (max_square, tmp ))
Puts ("right triangle. ");
Else if (max_square <tmp)
Puts ("acute triangle. ");
Else
Puts ("indecimal triangle. ");
}
}
Int main (void)
{
Char cs, ch;
Do
{
Input ();
Sort ();
Judge ();
If (input_err_flag)
{
Input_err_flag = 0;
While (cs = getchar ())! = 'N' & (cs = getchar ())! = EOF );
Printf ("input error, a B c must be greater than zero, whether new input (y/n ):");
}
Else if (judge_err_flag)
{
Judge_err_flag = 0;
While (cs = getchar ())! = 'N' & (cs = getchar ())! = EOF );
Printf ("if the group is not a triangle, whether to re-input (y/n ):");
}
Else
{
While (cs = getchar ())! = 'N' & (cs = getchar ())! = EOF );
Printf ("whether to input another set of data (y/n ):");
}
Ch = getchar ();
}
While (ch = 'y' | ch = 'n ');
Puts ("Goodbye! ");
Return 0;
}