How to judge the triangular type _c language by C-language applet

Source: Internet
Author: User
Tags abs float max
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 ("The right-angled triangle." ");
else if (Max_square < TMP)
Puts ("acute triangle.") ");
Else
Puts ("obtuse.") ");
}
}
int main (void)
{
Char CS, ch;
Todo
{
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 ');
Puts ("goodbye!");
return 0;
}

Related Article

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.