Server IP : 172.16.15.8 / Your IP : 18.117.94.77 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/jmmowatt/../drsparks/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// File Name: array.cpp // // Class: CS 212 Comp. Prog. II // Author: Dale Sparks // Instructor: Dr. Wang // Date: Feb. 09, 2008 // Compile: g++ array.cpp -o array.out // Run: ./array.out // // Goal: The program allows the user to input 10 numbers then // finds the smallest, the largest, and the average of // the numbers. #include <iostream> using namespace std; const int MAX = 10; void readNum (int[]); // fun. prototype int smallest(const int data[]); // fun. prototype int largest(const int data[]); // fun. prototype float average(const int data[]); // fun. prototype int main() { int num[MAX]; int small, large; float averag; // read the date to array readNum(num); // find the smallest small = smallest(num); // find the largest large = largest(num); // find the average averag = average(num); // output cout << "The Smallest is: " << small; cout << "\nThe Largest is: " << large; cout << "\nThe Average is: " << averag; cout << "\n\nDone. Bye-Bye.\n\n"; return 0; } // funtcion that read 10 numbers to an array. void readNum(int num[]) { for(int i=0; i<10; i++) cin >> num[i]; } // find the smallest int smallest(const int data[]) { int s = data[0]; for(int i=0; i<10; i++) { if (s > data[i]) s = data[i]; } return s; } // find the largest int largest(const int data[]) { int l = data[0]; for(int i=0; i<10; i++) { if (l < data[i]) l = data[i]; } return l; } // find the average float average(const int data[]) { int num=0; float avg=0, total=0; for(int i=0; i<10; i++) { num++; total += data[i]; } avg = total / num; return avg; }