> 其他 >
c语言程序设计 输入三角形的3条边a,b,c,如果能构成三角形,输入面积crea和周长preimeter(保留两位小数)
人气:229 ℃ 时间:2020-04-14 13:52:42
解答
#include
#include
void main(void)
{
double a, b, c, S, p;
int TRUE = 0;
printf("Enter three numbers for sides of a triangle: ");
scanf("%lf %lf %lf", &a, &b, &c);
if((a + b > c) && (b + c > a) && (c + a > b))
{
TRUE = 1;
p = (a + b + c) / 2;
S = sqrt(p * (p - a) * (p - b) * (p - c));
}
if(TRUE == 1)
{
printf("\nThese three sides can structure a triangle.\n");
printf("The area of the triangle is %.2f.\n", S);
printf("The perimeter of the triangle is %.2f.\n", 2 * p);
}
}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版