首页 > 技术文章 > 海伦公式已知三边求面积

ant-xu 2019-07-06 13:30 原文

已知三边求面积

import math

a = float(input('a = '))
b = float(input('b = '))
c = float(input('c = '))
if a + b > c and a + c > b and b + c > a:
    print('周长: %f' % (a + b + c))
    s = (a + b + c) / 2
    area = math.sqrt(s * (s - a) * (s - b) * (s - c))
    print('面积: %f' % (area))
else:
    print('不能构成三角形')

证明

s是周长的一半。海伦公式https://zh.wikipedia.org/zh-hans/%E6%B5%B7%E4%BC%A6%E5%85%AC%E5%BC%8F

推荐阅读