标签:
#include <iostream> using namespace std; #define length1 3 #define length2 5 //*****找出最大值***** int Largest(int list[],int length) { int i,max=list[0]; for(i=0;i<length;i++) { if(list[i]>max) { max=list[i]; } } return max; } int main(int argc, char* argv[]) { int max1,max2,i; int list1[length1];//={10,22,62,45,28,0,-78,-5,3,10}; int list2[length2];//={-5,-4,-3,-2,-1}; cout<<"请输入"<<length1<<"个数:"; for(int i=0;i<length1;i++) cin>>list1[i]; cout<<"请输入"<<length2<<"个数:"; for(i=0;i<length2;i++) cin>>list2[i]; max1=Largest(list1,length1); max2=Largest(list2,length2); cout<<endl<<"list1:"; for(i=0;i<length1;i++) cout<<list1[i]<<" "; cout<<endl<<"最大值:"<<max1<<endl; cout<<"list2:"; for(i=0;i<length2;i++) cout<<list2[i]<<" "; cout<<endl<<"最大值:"<<max2<<endl<<endl; return 0; }
标签:
原文地址:http://www.cnblogs.com/lq897897/p/5609984.html