In: Computer Science
Write C++ program to do the following:
1. Create integer array size of 10
2. Ask user input the values of the array's element using for
loop
3. pass the array to void function. in void function do the
following:
a. Find the maximum of the array.
b. Compute the element average
c. Find out how many numbers are above the average
d. Find out and print how many numbers are below the average
e. find out how many numbers are equal to he average.
#include<iostream>
using namespace std;
void fun(int InputNum[])
{
float maxi=InputNum[0];
int above_avg_cnt=0;
int below_avg_cnt=0;
int equal_avg_cnt=0;
//find max
float sum=0;
for(int i=0;i<10;i++)
{
if(maxi<InputNum[i])
maxi=InputNum[i];
sum+=InputNum[i];
}
float avg=sum/10;
for(int i=0;i<10;i++)
{
if(InputNum[i]>avg)
above_avg_cnt++;
if(InputNum[i]<avg)
below_avg_cnt++;
if(InputNum[i]==avg)
equal_avg_cnt++;
}
cout<<"Maximum of the array is:
"<<maxi<<endl;
cout<<"Average of the array is:
"<<avg<<endl;
cout<<"element above the average:
"<<above_avg_cnt<<endl;
cout<<"element below the average:
"<<below_avg_cnt<<endl;
cout<<"element equal to the average:
"<<equal_avg_cnt<<endl;
}
int main()
{
int n=10;
int arr[n];
cout<<"Enter 10 element: ";
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
fun(arr);
}