#include <iostream>
using namespace std;
double average;
***** *****(*****)
{
int x,themax,sum,i;
cin>>x;
*****;
sum=x;
for(i=*****;i<=*****;i++)
{
cin>>x;
if(x>themax)
*****;
sum+=x;
}
average=*****;
return *****;
}
void main()
{
int n,max;
cin>>*****;
max=find(*****);
cout<<*****<<' '<<average<<endl;
}
输入
输入要计算的数字个数n,再依次输入n个整数。
输出
n个数中的最大值和平均值
难度
较难
输入示例
5
2 3 1 8 4
输出示例
8 3.6
#include <iostream>
using namespace std;
double average;
int find(int n) {
int x,themax,sum,i;
cin>>x;
themax=x;
sum=x;
for(i=2; i<=n; i++) {
cin>>x;
if(x>themax)
themax=x;
sum+=x;
}
average=sum*1.0/n;
return average;
}
void main() {
int n,max;
cin>>n;
max=find(n);
cout<<max<<' '<<average<<endl;
}