【考研每日一題26】求最大值(C++)

原題地址:牛客網

題目描述

輸入10個整數,要求輸出其中的最大值。

輸入描述:

測試數據有多組,每組10個整數。

輸出描述:

對於每組輸入,請輸出其最大值(有回車)。

示例1

輸入

10 22 23 152 65 79 85 96 32 1

輸出

max=152

代碼:

#include<iostream>
using namespace std;
int main()
{
    int a[10];
    while(cin>>a[0])
    {
        int sum=a[0];
        for(int i=1;i<=9;i++)
        {
            cin>>a[i];
            if(a[i]>sum)sum=a[i];
        }
        cout<<"max="<<sum<<endl;
    }
    return 0;
}

2020.4.14

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章