rwkj 1293 三角形的种类

C语言:选择结构5(三角形的种类)
时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
总提交:885 测试通过:506

描述


输入三角形的3条边长(均为正整数),如果不能构成一个三角形,则输出“not a triangle”;如果能够构成一个直角三角形,则输出“yes”;如果不能构成直角三角形,则输出“no”。

请将下面的程序填写完整。

#include <stdio.h>
int main()
{ int a,b,c;
while (scanf("%d%d%d",&a,&b,&c)!=EOF)
{ .............................

..........................

}
return 0;
}

输入


包括多组数据,每组3个正整数。


输出

根据题目意思输出相应的结果。

样例输入

3 4 5
3 4 6
3 5 1
5 4 3

样例输出

yes
no
not a triangle
yes


#include <iostream.h>
using namespace std;
int main()
{
int a,b,c;
while (scanf("%d%d%d",&a,&b,&c)!=EOF)
{
if (a+b>c&&a+c>b&&c+b>a)
{
if (a*a+b*b==c*c||a*a+c*c==b*b||c*c+b*b==a*a)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else cout<<"not a triangle"<<endl;
}
return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{ int a,b,c;

while (scanf("%d%d%d",&a,&b,&c)!=EOF)
{ if (a*a==b*b+c*c ||b*b==a*a+c*c ||a*a+b*b==c*c)
printf("yes ");
else if (a+b<c || a+c<b ||b+c<a)
printf("not a triangle ");
else printf("no ");
}

return 0;
}

原文地址:https://www.cnblogs.com/2014acm/p/3911210.html