c++数组。输入10个数,输出这10个数中的最大值,最小值。

 1 #include<iostream>
 2 using namespace std;
 3  
 4 int main() {
 5     int a[10];
 6     int min=0, max=0;
 7     cout << "Please enter 10 integer:" << endl;
 8     for(int i=0; i<10; i++) 
 9     {
10         cin >> a[i];
11     }
12     min = a[0];
13     max = a[0];
14     for(int i=0; i<10; i++) 
15     {
16         if(a[i]>max) 
17         {
18             max = a[i];
19         }
20         if(a[i]<min) 
21         {
22             min = a[i];
23         }
24     }
25     cout << "max: " << max << endl;
26     cout << "min: " << min << endl;
27     return 0;
28 }

 

posted @ 2015-05-12 13:37  php-study  阅读(4749)  评论(0编辑  收藏  举报