c语言程序设计 输入三角形的3条边a,b,c,如果能构成三角形,输入面积crea和周长preimeter(保留两位小数)

如题所述

#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);
}
}

参考资料:http://baike.baidu.com/view/1279.html

温馨提示:答案为网友推荐,仅供参考