C++ 求一维数组中各元素的最大值、最小值和平均值

2023-07-26 14:18发布

#includeusing namespace std;void process(float a[],int n) { float min,

#includeusing namespace std;void process(float a[],int n) { float min,
3条回答
2023-07-26 14:50 .采纳回答

#include<iostream>
using
namespace
std;
void
process(float
a[],int
n)
{
float
min,max;
int
i=0;
for(i=0,max=min=a[0];i<n;i++){
if(min>a[i])min=a[i];
if(max<a[i])max=a[i];
}
cout<<"
min="<<min;
cout<<",max="<<max<<"
";
}
void
print(float
a[],int
n)
{
for(int
i=
0;i<n;i++)
{
if(i%6==0)cout<<"
";
cout<<a[i]<<"
";
}
}
void
main()
{
float
a[24]={2,1,4,45,23,33,-7,8,5,9,0,-4,66,12,55,33,32,11,63,14,88,-9,23,6};
print(a,24);
process(a,24)
;
}

一周热门 更多>