Question one hundred and thirty-six: triangle Problems

Source: Internet
Author: User

[Plain] # include <stdio. h>
# Include <math. h>
# Include <stdlib. h>
 
Float calculate_perimeter (float x, float y, float z );
Float calculate_area (float x, float y, float z );
Int judge_triangle (float x, float y, float z );
Int judge_righttriangle (float x, float y, float z );
Int judge_isoscelestriangle (float, float y, float z );
Int judge_equilateraltriangle (float x, float y, float z );
Int main ()
{
Float x;
Float y;
Float z;

Scanf ("% f", & x, & y, & z );

If (judge_triangle (x, y, z ))
{
Printf ("The area of a triangle is % f. \ nThe perimeter of a triangle is % f. \ n ",
Calculate_area (x, y, z), calculate_perimeter (x, y, z ));
If (judge_righttriangle (x, y, z ))
{
Printf ("The triangle is right triangle! \ N ");
}
Else
{
Printf ("The triangle is not right triangle! \ N ");
}

If (judge_isoscelestriangle (x, y, z ))
{
Printf ("The triangle is isoscelestriangle! \ N ");
}
Else
{
Printf ("The triangle is not isoscelstriangle \ n ");
}

If (judge_equilateraltriangle (x, y, z ))
{
Printf ("The triangle is equilateraltriangle! \ N ");
}
Else
{
Printf ("The triangle is not equlateraltriangle! \ N ");
}
}
Else
{
Printf ("x, y and z cann't form a triangle! \ N ");
}

System ("pause ");
Return 0;
}
 
// Definetion of function
// ** Judge triangle
Int judge_triangle (float x, float y, float z)
{
Int flag;

Flag = 0;

If (x + y> z | x + z> y | y + z> x)
{
Flag = 1;
}

Return flag;
}
 
// ** Calculate perimeter
Float calculate_perimeter (float x, float y, float z)
{
Float perimeter;

Perimeter = x + y + z;

Return perimeter;
}
 
// ** Calculate area
Float calculate_area (float x, float y, float z)
{
Float s;
Float area;

S = calculate_perimeter (x, y, z)/2;
Area = sqrt (s-x) * (s-y) * (s-z) * s );

Return area;
}
 
// ** Judge righttriagnle
Int judge_righttriangle (float x, float y, float z)
{
Int flag;

Flag = 0;

If (x * x + y * y = z * z | x * x + z * z = y * y | z * z + y * y = x * x)
{
Flag = 1;
}

Return flag;
}
 
// ** Judge isoscelestriangle
Int judge_isoscelestriangle (float x, float y, float z)
{
Int flag;

Flag = 0;

If (x = y | x = z | y = z)
{
If (x = y & y = z & x = z)
{
Flag = 0;
}
Else
{
Flag = 1;
}
}

Return flag;
}
 
// ** Judge equilateraltriangle
Int judge_equilateraltriangle (float x, float y, float z)
{
Int flag;

Flag = 0;

If (x = y & y = z & x = z)
{
Flag = 1;
}

Return flag;
}

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.