问题描述:
找找谁的身高超过全家的平均身高。
全家 n 口人,输入输出数据如下: (平均身高保留一位小数)。
输入
第一行有一个整数 𝑛 ( 1<𝑛<11 );
第二行是 𝑛个整数,用空格隔开。
输出
第一行为全家的平均身高(保留一位小数);
第二行有若干个数,为超过平均身高的人的身高厘米数。
附上代码:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,m;
float AVE=0;
cin>>n;
m=n;
int arr[n];
if(n>1&&n<11)
{
for(int n=0;n<m;n++)
{
scanf("%d",&arr[n]);
AVE=AVE+arr[n];
}
AVE=AVE/m;
cout<<"AVE="<<fixed<<setprecision(1)<<AVE<<endl;
for(int n=0;n<m;n++)
{
if(arr[n]*1.0>=AVE)
cout<<n+1<<":"<<arr[n]<<" ";
}
}
return 0;
}