乐乐学编程 发表于 2020-11-28 16:59:51

平面几何问题之三角形的面积

已知三角形的三个顶点,求三角开的面积

风过无痕1989 发表于 2020-11-28 17:06:34

这题目以前做过练习,直接复制给你好了
#include <stdio.h>
#include <math.h>
double S_tri(double ax, double ay, double bx, double by, double cx, double cy)
{
        double S;
        S = 0.5 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by));
        if (S >= 0)
                return S;
        else
                return (-1.0 * S);
}
void main()
{
        double S, ax, ay, bx, by, cx, cy;
        scanf("%lf%lf%lf%lf%lf%lf", &ax, &ay, &bx, &by, &cx, &cy);
        S = S_tri(ax, ay, bx, by, cx, cy);
        printf("S_triangle = %lf\n", S);
}

风过无痕1989 发表于 2020-11-28 17:07:41

#include <stdio.h>
#include <math.h>
double S_tri(double ax, double ay, double bx, double by, double cx, double cy)
{
        double S;
        S = 0.5 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by));
        if (S >= 0)
                return S;
        else
                return (-1.0 * S);
}
void main()
{
        double S, ax, ay, bx, by, cx, cy;
        scanf("%lf%lf%lf%lf%lf%lf", &ax, &ay, &bx, &by, &cx, &cy);
        S = S_tri(ax, ay, bx, by, cx, cy);
        printf("S_triangle = %lf\n", S);
}
页: [1]
查看完整版本: 平面几何问题之三角形的面积