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

时间:2015-05-12 15:16:07   收藏:0   阅读:113
 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 }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!