Average - cout << y[i] << " " ; }...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// Determine the number of elements in an array // greater than the average // Author: Chuck Swanson, modifications by Eric Van Wyk. #include<iostream> using namespace std; int main() { const int NEL = 10; int i, count = 0; double avg = 0.0; //declare and initialize an array double y[] = {88.7, 77.9, 84.3, 99.2, 56.7, 65.5, 70.2, 80.5, 91.5, 55.8}; // display the array for(i=0; i < NEL; i++) {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout << y[i] << " " ; } cout << endl; // get the average double sum = 0.0 ; for(i=0; i < NEL; i++) { sum += y[i]; } avg = sum / NEL; cout << "Average = " << avg << endl; // determine the number greater than the average for(i=0; i < NEL; i++) { if( y[i] >= avg ) count++; } cout << "There are " << count << " elements greater than the average\n"; return 0; }...
View Full Document

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Ask a homework question - tutors are online