123 C++試寫一演算法,求隨機輸入的三個整數的最大值

phpstory發表於2018-08-28

試寫一演算法,求隨機輸入的三個整數的最大值。 

#include<iostream>
using namespace std;

int max(int x, int y, int z)
{
	int t;
	t = x > y ? x : y;
	t = t > z ? t : z;
	return z;
}

int main()
{
	int x,y,z,Max;
	cin >> x;
	cin >> y;
	cin >> z;
	Max = max(x,  y, z);
	cout << "最大值是:" << Max << endl;
	return 0;
}

4 5 6
最大值是:6
請按任意鍵繼續. . .

只寫int max就行了。

相關文章