The first to judge the type of triangle, two floating-point data can not directly judge the equality, for the convenience of input, set their own low precision, 10^ ( -3)
Copy code code as follows:
#include <stdio.h>
#include <stdlib.h>
#define Epsinon 1e-3
#define ABS (A) (((a) >0)? ( A):(-a))//? : expression nesting is not supported
#define ZERO (x) ((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 ("Enter a value of three edges:");
scanf ("%f%f%f", &a, &b, &c);
if (!) ( a>0) | | ! (b>0) | | ! (c>0))
{
Input_err_flag = 1;
}
}
void sort (void)
{
max = max (max (a,b), c);
min = 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 ("equilateral"). ");
Else if (equal (Max_square, TMP))
puts ("isosceles right-angled triangle." ");
else if (Max_square < TMP)
puts ("Isosceles acute triangle". ");
Else
puts ("Isosceles obtuse". ");
}
Else
{
if (Equal (min, mid))
puts ("equilateral"). ");
Else
puts ("Isosceles acute triangle". ");
}
}
Else if (equal (Max_square, TMP))
puts ("right-angled triangle"). ");
else if (Max_square < TMP)
puts ("acute triangle"). ");
Else
puts ("obtuse"). ");
}
}
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 0, new input (y/n):");
}
else if (judge_err_flag)
{
judge_err_flag = 0;
while ((Cs=getchar ())!= ' n ' && (Cs=getchar ())!=eof);
printf ("Group is not triangular, re-enter (y/n):");
}
Else
{
while ((Cs=getchar ())!= ' n ' && (Cs=getchar ())!=eof);
printf ("Enter a second set of data (y/n):");
}
ch = getchar ();
}
while (ch== ' y ' | | | | ch== ' y ' | | | ch== ' n ');
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.