View Code of Problem 24

#include <stdio.h>
#include <math.h>
int main()
{
    double a,b,c,p,s;
    scanf("%lf%lf%lf",&a,&b,&c);
    if(a+b>c && a+c>b && b+c>a) //判断是否可以构成三角形。
    {
        p=(a+b+c)/2;//计算半周长
        s=sqrt(p*(p-a)*(p-b)*(p-c));//套用海伦公式,计算面积
        printf("面积为%lf\n", s);//输出结果
    }
    else printf("无法构成三角形\n");//输入不合法,提示。
    return 0;
}

Double click to view unformatted code.


Back to problem 24