Type judgment and area calculation of triangles

In some graphics calculations and applications, it is often necessary to perform calculations and processing on triangles, and these calculations and processing have also been transformed into processing for the structure of the triangle.

  • Program design:
    The user is required to input the lengths of the three sides of the triangle, determine the type of the triangle, and find the area of ​​the triangle.
#include<iostream>
#include<cstdlib>
using namespace std;

typedef struct Triangle
{
    double a;
    double b;
    double c;
}Triangle;

int main()
{
    //要求用户输入三角形的三条边长,判断三角形的类型,并求出三角形的面积
ERROR1:cout << "不能组成三角形" << endl;

    Triangle T;

    cout << "Please Input three Lins:";
    cin >> T.a;
    cin >> T.b;
    cin >> T.c;

    double MaxTwoLin = T.a > T.b ? T.a : T.b;
    double x = T.a + T.b - MaxTwoLin;  //两边较小者
    double z = MaxTwoLin > T.c ? MaxTwoLin : T.c;  //三边最大者
    double y = T.a + T.b + T.c - x - z;  //第三边

    if (x + y <= z || z - x >= y)
    {
        goto ERROR1;
        cout << endl;
        return 0;
    }

    char *pType = NULL;
    if (z*z == x*x + y*y)
    {
        pType = "直角";
    }
    else if (z*z < x*x + y*y)
    {
        pType = "锐角";
    }
    else
    {
        pType = "钝角";
    }

    cout << "三角形类型是:" << pType << endl;
    cout << endl;

    return EXIT_SUCCESS;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325728985&siteId=291194637
Recommended