int main(void)
{
int x = -1, y[3] = {0} ;
cout << "請輸入三個數:" << endl ;
for( int i = 0 ; i <= 2 ; i++ ) {
cin >> y ;
if ( y > x )
x = y ;
}
cout << endl << "最大值為:" << x << endl;
return 0;
}
範例
#include <iostream>
using namespace std;
int main(void)
{
int i =0;
cout << "請輸入一整數:";
cin >> i;