首页 > 试题广场 >

计算三角形的周长和面积

[编程题]计算三角形的周长和面积
  • 热度指数:58716 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
根据给出的三角形3条边a, b, c,计算三角形的周长和面积。

数据范围:

输入描述:
一行,三角形3条边(能构成三角形),中间用一个空格隔开。


输出描述:
一行,三角形周长和面积(保留两位小数),中间用一个空格隔开,输出具体格式详见输出样例。
示例1

输入

3 3 3

输出

circumference=9.00 area=3.90
temp = input()
a,b,c = temp.split(" ")
a = int(a)
b = int(b)
c = int(c)
circle = a+b+c
if (a+b>c)&(a+c>b)&(b+c>a):
    p2 = (a+b+c)
    p = p2/2
    square =(p*(p-a)*(p-b)*(p-c))**0.5
print('circumference={:.2f} area={:.2f}'.format(circle,square))
难点应该是海伦公式,最后的格式化输出

发表于 2021-05-01 18:05:03 回复(0)
a,b,c = map(int,input().split(' '))
cir = a+b+c
s = cir/2
area = (s*(s-a)*(s-b)*(s-c))**0.5
print('circumference={:.2f} area={:.2f}'.format(cir,area))

发表于 2021-04-05 17:01:52 回复(0)
a,b,c = map(int, input().split())
cir = a+b+c
p = cir / 2
s = (p*(p-a)*(p-b)*(p-c))**(1/2)
print("circumference=%.2f area=%.2f" % (cir,s))

发表于 2021-02-26 14:20:01 回复(0)
a,b,c=map(int,input().split(' '))
cir=a+b+c 
p=cir/2
area=(p*(p-a)*(p-b)*(p-c))**0.5
print('circumference=%.2f area=%.2f'%(cir,area))

发表于 2021-01-31 12:12:22 回复(0)
s=input().split(' ')
a=int(s[0])
b=int(s[1])
c=int(s[2])
if (a + b > c) & (a + c > b) & (b + c > a):
    d=(a+b+c)
    p=d/2
    s = (p*(p-a)*(p-b)*(p-c))**0.5
print('circumference={:.2f} area={:.2f}'.format(d,s))

发表于 2020-08-04 11:38:19 回复(0)
a,b,c = input().split(' ')
a = int(a)
b = int(b)
c = int(c)
d = a + b + c
p = d/2
s = (p*(p-a)*(p-b)*(p-c))**0.5 #根据海伦公式,计算三角形的面积
print("circumference={:.2f} area={:.2f}".format(d,s))

发表于 2020-06-01 17:25:32 回复(0)
data=input()
data=data.split(" ")
a=eval(data[0])
b=eval(data[1])
c=eval(data[2])
length=a+b+c
p=length/2
s=(p*(p-a)*(p-b)*(p-c))**(1/2)
print("circumference={:.2f} area={:.2f}".format(length,s))

发表于 2020-05-11 16:01:53 回复(0)