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";

}

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";

}

Learn more about our help with Assignments: C++

## Comments

## Leave a comment