98 928
Assignments Done
98.6%
Successfully Done
In April 2021

# Answer to Question #12754 in C++ for Emmanuel

Question #12754
a program that accepts 20 numbers from a user, sieves and pick the even numbers from the 20 numbers and compute the arithmetic mean.displaying all the even numbers collected and the mean using functions.
1
2012-08-10T10:05:29-0400
#include <iostream.h>

bool even(int i){
if (i%2==0) return true;
else return false;
}

int m = 0, k = 0, i, arr[20];
void mean(){
for (i=0;i<20;i++){
& if (even(arr[i])){
& m += arr[i];
& k++;
& }
}
}

void main(){
for (i=0;i<20;i++){
& cout<<"enter a number: ";
& cin>>arr[i];
}
cout<<"\nHere are all entered numbers:\n";
for (i=0;i<20;i++){
& cout<<arr[i]<<" ";
}
cout<<"\n\nHere are entered even numbers:\n";
for (i=0;i<20;i++){
& if (even(arr[i])) cout<<arr[i]<<" ";
}

mean();

if (k!=0){
& m = m/k;
& cout<<"\nArithmetic mean of entered even numbers is "<<m;
}
else cout<<"\nThere are no even numbers.";
cout<<"\n\n";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!