60 721
Assignments Done
97,9%
Successfully Done
In April 2018

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.
Expert's answer
#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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions