热心网友
回答时间:2025-01-16 02:50
程序代码:#include <stdio.h>
#include <math.h>
void main()
{
float a,b,c,p=0,s=0;
printf("Please input a:");
scanf("%f",&a);
printf("please input b:");
scanf("%f",&b);
printf("please input c:");
scanf("%f",&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("Triangle S:%f\n",s);
}
else
{
printf("a,b,c can not be made of triangle~!\n");
}} 运行结果:
收起
热心网友
回答时间:2025-01-16 02:52
我是用C的 上楼以有C++了#include "stdio.h"
#include "math.h" //因为要用到数学平方sqrt
void main()
{
double a , b, c , C, s;
printf("请输入三个实数:"); scanf("%lf%lf%lf",&a,&b,&c);
if( (a+b>c)&&(a+c>b)&&(b+c>a) ) //判断三角形 二边之和大于第三边
{
C=(a+b+c)/2;
s=sqrt(C*(C-a)*(C-b)*(C-c));
printf("三角形面积为:%0.2lf\n",s);
}
else
{
printf("a,b,c 不能构成三角形\n");
}}
有不懂请追问 我的回答愿对 LZ 有所帮助
收起