2025-03-06 19:56:07 +08:00

36 lines
823 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
输入三角形三边长,判断能否构成三角形,如能构成则输出其面积,不能则给出错误提示。
(海伦公式):
一个三角形边长分别为a、b、c面积S可由一下公式求得
S=√p(p-a)(p-b)(p-c)
公式里p为半周长周长的一半P=(a+b+c)/2
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
/**********Program**********/
double S(int a, int b, int c){
return (a+b+c)/2;
}
double AREA(double t, int a, int b, int c){
return sqrt(t*(t-a)*(t-b)*(t-c));
}
/********** End **********/
main()
{
int a,b,c;
double t,area;
printf("请输入三个正整数,表示三角形的三个边长:");
scanf("%d%d%d",&a,&b,&c);
if(a+b>c&&a+c>b&&b+c>a)
{
t=S(a,b,c);
area=AREA(t,a,b,c);
printf("三角形的面积是:%f\n",area);
}
else
printf("不能构成三角形\n");
}