How does a C-language applet determine the triangle type?

Source: Internet
Author: User
Tags float max

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.