输入三角形三边边长 计算三角形面积
大一的 Python!
a = int(input('边长1:'))
b = int(input('边长2:'))
c = int(input('边长3:'))
p = (a+b+c)/2
s = (p*(p-a)*(p-b)*(p-c)) ** 0.5
print('三角形的面积为:', s)
如果有用望采纳
python
side1 = float(input("请输入第一条边"))
side2 = float(input("请输入第二条边"))
side3 = float(input("请输入第三条边"))
half = (side1 + side2 + side3) / 2
area = (half * (half - side1) * (half - side2) * (half - side3)) ** 0.5
print(area)
C语言
#include <stdio.h>
#include <math.h>
int main()
{
double side1, side2, side3;
double half;
scanf("%lf%lf%lf",&side1, &side2, &side3);
half = (side1 + side2 + side3) / 2.0;
double area = sqrt(half * (half - side1) * (half - side2) * (half - side3));
printf("三角形面积为:%.2lf\n",area);
return 0;
}
a = int(input('请输入第 1 边:'))
b = int(input('请输入第 2 边:'))
c = int(input('请输入第 3 边:'))
if a > 0 and b > 0 and c > 0 and a + b > c and a+c > b and b + c > a:
if a == b == c:
p = (a + b + c) / 2
s = (p * (p - a) * (p - b) * (p - c)) ** 0.5
print(f'等边三角形面积为:{s}')
elif a == b or a == c or b == c:
p = (a + b + c) / 2
s = (p * (p - a) * (p - b) * (p - c)) ** 0.5
print(f'等腰三角形面积为:{s}')
elif (a**2+b**2 == c**2) or (b**2+c**2 == a**2) or (a**2+c**2 == b**2):
p = (a + b + c) / 2
s = (p * (p - a) * (p - b) * (p - c)) ** 0.5
print(f'直角三角形面积为:{s}')
else:
p = (a + b + c) / 2
s = (p * (p - a) * (p - b) * (p - c)) ** 0.5
print(f'普通三角形面积为:{s}')
else:
print('不能组成三角形')