编写一个程序根据输入的三角形的三条边判断是否能组成三角形,如果可以则输出它的面积和三角形类型(等边、等腰、直角三角形

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

double a,b,c;

double v,p;

cout<<"请输入三角形三条边:"<<endl;

cin>>a>>b>>c;

if(a+b>c&&a+c>b&&b+c>a)

{

p=(a+b+c)/2;

v=sqrt(p*(p-a)*(p-b)*(p-c));

cout<<"该三角形面积是"<<v<<endl;

if(a==b&&a==c)

cout<<"该三角形是等边三角形!"<<endl;

else

if(a==b&&a!=c||a==c&&a!=b||b==c&&b!=a)

cout<<"该三角形是等腰三角形!"<<endl;

if((a*a+b*b==c*c)||(a*a+c*c==b*b)||(c*c+b*b==a*a))

cout<<"该三角形是直角三角形!"<<endl;

}

else

cout<<"这三条边组不成三角形!"<<endl;

return 0;

}

猜你喜欢

转载自blog.csdn.net/wyongkang/article/details/81102727