输入三个正整数,判断用这三个整数做边长是否能构成一个直角三角形

冒泡排序

# include<stdio.h>
int main()
{
	int a,b,c,x[3];
	for(a=0;a<3;a++)
	{
		scanf("%d",&x[a]);
	}
	for(a=0;a<2;a++) //冒泡排序
	{
		for(b=0;b<2-a;b++)
		{
			if(x[b]<x[b+1])
			{
				c=x[b+1];
				x[b+1]=x[b];
				x[b]=c;
			}
		}
	}
	if(x[0]*x[0]==x[1]*x[1]+x[2]*x[2])
	{
		printf("yes");
	}
	else
	{
		printf("no");
	}
	return 0;
}

选择排序

# include<stdio.h>
int main()
{
	int a,b,c,x[3],max;
	for(a=0;a<3;a++)
	{
		scanf("%d",&x[a]);
	}
	for(a=0;a<2;a++)
	{
		max=a;
		for(b=1;b<3;b++)
		{
			if(x[max]<x[b])
			{
				max=b;
			}
		}
			c=x[a];
			x[a]=x[max];
			x[max]=c;
	}
	if(x[0]*x[0]==x[1]*x[1]+x[2]*x[2])
	{
		printf("yes");
	}
	else
	{
		printf("no");
	}
	return 0;
}

插入排序

# include<stdio.h>
int main()
{
	int a,b,c,x[3],max;
	for(a=0;a<3;a++)
	{
		scanf("%d",&x[a]);
	}
	for(a=1;a<3;a++)
	{
		max=x[a];//标记数值
		b=a-1;
		while((b>=0)&&(x[b]<max))
		{
			x[b+1]=x[b];
			b--;
		}
		x[b+1]=max;//进行交换
	}
	if(x[0]*x[0]==x[1]*x[1]+x[2]*x[2])
	{
		printf("yes");
	}
	else
	{
		printf("no");
	}
	return 0;
}
发布了43 篇原创文章 · 获赞 1 · 访问量 831

猜你喜欢

转载自blog.csdn.net/Du798566/article/details/104179867