通过函数求一组数组中最大最小的函数

一、代码

 1 #include <iostream>
 2 using namespace std;
 3 //求整形数组中最大的元素
 4 int imax(int array[],int count)
 5 {
 6     int temp=array[0];
 7     for (int i=0;i<count;i++)
 8     {
 9         if(temp<=array[i])
10             temp=array[i];
11     }
12     cout<<"最大的数为:"<<temp<<endl;
13     return 0;
14 
15 }
16 //求整形数组中最小的元素
17 int imin(int array[],int count)
18 {
19     int temp=array[0];
20     for (int i=0;i<count;i++)
21     {
22         if(temp>=array[i])
23             temp=array[i];
24     }
25     cout<<"最小的数为:"<<temp<<endl;
26     return 0;
27 }
28 //主函数
29 void main()
30 {
31     cout<<"请输入数字的个数:"<<endl;
32     int MaxSize=0;
33     cin>>MaxSize;
34     int *Array=new int[MaxSize];
35     cout<<"请输入"<<MaxSize<<"个数字:"<<endl;
36     for (int i=0;i<MaxSize;i++)
37     {
38         cin>>Array[i];
39     } 
40     imax(Array,MaxSize);
41     imin(Array,MaxSize);
42 }

二、运行

原文地址:https://www.cnblogs.com/f59130/p/3329242.html