求最大值
題目1046:求最大值
輸入:
輸出:
樣例輸入: 10 22 23 152 65 79 85 96 32 1
樣例輸出: max=152
#include<stdio.h> #include<iostream> using namespace std;int main() {while(true){int m[10];int k=0;for(k;k<10;k++){cin>>m[k];}int tmp;for(int i=1;i<10;i++){if(m[0]<=m[i]){tmp=m[0];m[0]=m[i];m[i]=tmp;}} cout<<m[0];} }
時間限制:1 秒
內(nèi)存限制:32 兆
特殊判題:否
提交:9145
解決:3738
題目描述:輸入10個數(shù),要求輸出其中的最大值。
測試數(shù)據(jù)有多組,每組10個數(shù)。
對于每組輸入,請輸出其最大值(有回車)。
樣例輸入:
#include<stdio.h> #include<iostream> using namespace std;int main() {while(true){int m[10];int k=0;for(k;k<10;k++){cin>>m[k];}int tmp;for(int i=1;i<10;i++){if(m[0]<=m[i]){tmp=m[0];m[0]=m[i];m[i]=tmp;}} cout<<m[0];} }
總結(jié)