请教一下,用C语言编程,给出三角形的三条边,求三角形的面积?怎么弄?

来源:百度知道 编辑:UC知道 时间:2024/05/27 06:58:24
可以

#include <stdio.h>
#include <math.h>

int main()
{
float a,b,c,h,s;
scanf("%f %f %f",&a,&b,&c);
h=(a+b+c)/2;
s=sqrt(h*(h-a)*(h-b)*(h-c));
printf("%g\n",s);

return 0;
}

利用海伦公式
#include<stdio.h>
#include<math.h>
main(){
float a,b,c,p,s;
printf("\n输入三条边长:");
if(a+b>c|a+c>b|b+c>a)printf("此三边不能组成三角形");
else{
p=(a+b+c)/2;
s=sqrt(P*(p-a)*(p-b)*(p-c)); 海伦公式
printf("三角形的面积是:%f",s);
}
}

用C++可以吗?
#include<iostream>
using namespace std;

int main()
{
double a,b,c,d;
cout<<"输入三条边长: ";
cin>>a>>b>>c;
if (a+b<=c || b+c<=a||c+a<=b)
{
cout<<"不存在!"<<endl;
}
else
{
d=(a+b+c)/2;
cout<&