c语言实践 给三个数输出最大的那个数

我是怎么想的,我前面学过两个数比大小,比如有三个数,a b c,先比较a和b的大小,然后用那个较大的和c比较就得出最大的那个了。这个求三个数比大小的问题最后变化成 了两个数比大小了。

int main()
{
	int a = 0;
	int b = 0;
	int c = 0;
	int max2 = 0;//保存两个数中较大的那一个
	int max3 = 0;//保存三个数中最大的那一个

	scanf_s("%d %d %d",&a,&b,&c);

	//先找出a b中较大的那一个
	if (a > b)
	{
		max2 = a;
		if (max2 > c)
		{
			printf("%d is the greatest",max2);
		}
		else
		{
			printf("%d is the greatest",c);
		}
	}
	else
	{
		max2 = b;
		if (max2 > c)
		{
			printf("%d is the greatest",max2);
		}
		else
		{
			printf("%d is the greatest",c);
		}
	}



}

  

猜你喜欢

转载自www.cnblogs.com/yfish/p/9644157.html