Answer to Question #16295 in C++ for paul jimbo uy

Question #16295
make a c program to input 20 integers. output the average of all positive odd integers
1
Expert's answer
2012-10-15T12:12:51-0400
#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");
}


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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS