if(!(((a+b)>c))&&((a+c)>b)&&((c+b)>a)){
时间: 2024-05-27 11:14:23 浏览: 31
This is not a complete expression in programming. It is missing the condition that needs to be evaluated. A complete expression would be:
if (!(((a + b) > c)))
This expression checks if the sum of a and b is greater than c, and then negates the result. The "!" symbol in front of the expression means "not", so the condition in the if statement is true only if the sum of a and b is not greater than c.
相关问题
找出代码的错误#include<stdio.h> #include<math.h> int main(){ float l,a,b,c,area; printf("请输入三角形的三条边长:\n"); scanf("%d%d%d",&a,&b,&c); if(a+b>c&&a+c>b&&b+c>a) {l=(a+b+c)/2; area=sqrt(l*(l-a)*(l-b)*(l-c)); printf("面积为:%d\n",area);} else printf("不能组成三角形");} return 0;
这段代码有几个错误:
1. 在输入三角形三边长时,使用了 `%d` 格式符,应该使用 `%f`,因为三角形的边长通常是小数。
2. 计算三角形面积的公式写错了,应该是海伦公式:$s = \frac{a+b+c}{2}$,$area = \sqrt{s(s-a)(s-b)(s-c)}$。
3. 在输出面积时,使用了 `%d` 格式符,应该使用 `%f`,因为面积也通常是小数。
下面是修改后的代码:
```c
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, s, area;
printf("请输入三角形的三条边长:\n");
scanf("%f%f%f", &a, &b, &c);
if (a + b > c && a + c > b && b + c > a) {
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("面积为: %f\n", area);
} else {
printf("不能组成三角形\n");
}
return 0;
}
```
用python写根据海伦公式由三角形的三边长度a、b、c可以计算三角形面积 ,公式为: ,其中: 。请根据下列要求编写程序: ① 三角形面积的计算由函数getarea实现,当输入的a、b、c值不能构成三角形时,返回0.0;(提示:构成三角形的三边条件:任意两边之和大于第三边,或任意两边之差的绝对值小于第三边,例如:a+b>c&&a+c>b&&c+b>a ) ② 主函数的功能是输入三角形的三条边长,再调用getarea()得到面积,最后输出结果;
以下是根据要求编写的程序:
```python
import math
def getarea(a, b, c):
if a+b>c and a+c>b and c+b>a:
s = (a + b + c) / 2
area = math.sqrt(s * (s - a) * (s - b) * (s - c))
return area
else:
return 0.0
if __name__ == '__main__':
a = float(input('请输入三角形的第一条边长:'))
b = float(input('请输入三角形的第二条边长:'))
c = float(input('请输入三角形的第三条边长:'))
area = getarea(a, b, c)
print('三角形的面积为:%.2f' % area)
```
运行程序后,可以按照提示输入三角形的三条边长,程序会自动计算三角形的面积并输出结果。如果输入的三条边长不能构成三角形,则输出结果为0.0。