Question #16295

make a c program to input 20 integers. output the average of all positive odd integers

Expert's answer

#include<iostream>

using namespace std;

int p, N=0;

float s=0;

bool odd(int a){

if (a%2!=0) return true;

& else return false;

}

void main(){

for (int i=0; i<20; i++) {

& cout<<"enter a number: ";

& cin>>p;

& if ((p>=0)&&(odd(p))) { s += p; ++N; }

}

cout<<"The average of all positive odd integers is "<<s/N<<"\n";

system("pause");

}

using namespace std;

int p, N=0;

float s=0;

bool odd(int a){

if (a%2!=0) return true;

& else return false;

}

void main(){

for (int i=0; i<20; i++) {

& cout<<"enter a number: ";

& cin>>p;

& if ((p>=0)&&(odd(p))) { s += p; ++N; }

}

cout<<"The average of all positive odd integers is "<<s/N<<"\n";

system("pause");

}

## Comments

## Leave a comment