29.输入三个实数,判断能否构成三角形;若能,再说明是何种类型的三角形

#include<iostream>
using namespace std;

int main()
{
    int a,b,c;
    cout<<"please input a,b and c : "<<endl;
    cin>>a>>b>>c;

    if((a+b<c)||(a+c<b)||(b+c<a)||(a-b>=c)||(a-c>=b)||(b-c>=a)||(b-a>=c)||(c-a>=b)||(c-b>=a))//注意不要忘了有等于的情况
    {
        cout<<"can not be a triangle."<<endl;
    }else if((a*a==b*b+c*c)||(b*b==a*a+c*c)||(c*c==a*a+b*b))
    {
        cout<<"it is a right triangle(直角三角形)."<<endl;
    }else if(a==b&&b==c)//注意不能写成a==b==c
    {
        cout<<"it is an equilateral triangle(等边三角形)."<<endl;
    }
    return 0;
}

 

posted on 2014-08-06 18:41  Ji_xiaowu  阅读(1462)  评论(0编辑  收藏  举报

导航