首页 > 试题广场 >

判断直角三角形

[问答题]

判断直角三角形

内容:

输入三角形的三边,判断它是否是直角三角形,是输出Yes,不是输出No,连三角形都不是,输出Error

输入说明:

一行,输入3个整数

输出说明:

Yes! 或者 No!或者 Error! (注意大小写,标点前无空格)

输入样例:

3 4 5

输出样例:

Yes!

程序:

#include <cstdio> 
#include <iostream> 
using namespace std; 
 
int main() 
{ 
int a,b,c,i,j,temp; 
cin>>a>>b>>c;
if ((a+b<=c) || (a+c<=b) || (b+c<=a)) cout<<"Error!"; 
else if((a*a+b*b==c*c) || (a*a+c*c==b*b) || (b*b+c*c==a*a)) cout<<"Yes!"; 
else cout <<"No!";
return 0; 
} 

#include <stdio.h>
int main()
{
	int x, y, z;
	printf("输入三角形的三边长:\n");
	scanf("%d %d %d", &x, &y, &z);
    //判断是否为三角形
	if ((x + y > z)||(x+z>y)||(y+z>x))
	{//是三角形 则判断是否构成直角三角形
		if ((x*x + y*y == z*z)||(x*x+z*z==y*y)||(z*z+y*y==x*x))
			printf("Yes!\n");
		else
			printf("No!\n");
	}
	else
		printf("Error!\n");	
    return 0;
}

发表于 2022-05-07 17:49:26 回复(0)
#include <stdio.h>

int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if ((a + b <= c) || (a + c <= b) || (b + c <= a))
        printf("Error!");
    else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a)
        printf("Yes!");
    else
        printf("No!");
    return 0;
}

发表于 2022-03-25 14:26:01 回复(0)

include

include

using namespace std;
int main()
{
int a, b, c, j, i, tmp;
cin >> a >> b >> c;
if((a + b <= c) || (a + c << b) || (b + c <= a)) cout << "error" ;
else if((a a + b b == c * c) || (a * a + c * c == b * b) || b *b + c * c == a * a) cout << "yes";
else cout << "no";
return 0;

}

发表于 2020-08-08 15:35:54 回复(0)