判断三角形类型 018

来源:互联网 发布:淘宝转运网站 编辑:程序博客网 时间:2024/05/11 04:24
int main(){double longs, width, height;printf("请输入三条边长度:");scanf("%lf %lf %lf", &longs, &width, &height);double temp = (longs + width + height) / 2;double ret = sqrt(temp*(temp - longs) * (temp - width) * (temp - height));if (longs + width > height && longs + height > width && width + height > longs){if (longs == width && width == height && height == width){printf("等边三角形 面积为:%lf", (longs*height)*0.5);}else if (longs == width || longs == height || width == height){ /*海伦公式:三角形面积S = √[P(P - A)(P - B)(P - C)]  其中P = (A + B + C) / 2  A、B、C表示三角形的边长,√表示根号,即紧跟后面的括号内的全部数开根号*/printf("等腰三角形 面积为%lf", ret);}//直角三角形特征;两边的平方等于第三边的平方、else if (longs * longs + width *width == height*height || longs *longs + height*height == width *width || width * width + height*height == longs*longs){printf("直角三角形,面积为%lf",ret);}else{printf("普通三角形");}}else{printf("\n不能构成三角形");}system("pause");return 0;}


0 0