c语言程序设计 输入三角形的3条边a,b,c,如果能构成三角形,输入面积crea和周长preimeter(保留两位小数)
1个回答
展开全部
#include <stdio.h>
#include <math.h>
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);
}
}
#include <math.h>
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);
}
}
参考资料: http://baike.baidu.com/view/1279.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询