Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.15.203.242
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 (0755) :  /home/pswoodson/cs212/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/pswoodson/cs212/array.cpp
//// File name: paula.cpp
// Class: Cs 212 comp.prog. II
// Author: Paula S. Woodson
// Dr. Wang
// Due Date: Feb 1,2009
// Compile: g++ paula.cpp 
// Run: ./a.out
//-------------------------------------------------------------------------

#include <iostream>
#include <iomanip>
using namespace std;

const int MAX = 10;
void readNum(int []); // fun.prototype
int smallest(const int data[]);
int largest(const int data[]);
float aver(const int data[]);


int main()
{
  int num[MAX];
  int small;
  int large;
  float ave; 
// read the data to array 
 readNum(num); // call funtion
 

 // find the smallest
 small = smallest(num);
 large = largest(num);
 ave = aver(num); 
// out
 cout << "\nthe smallest is: " << small;
 cout << "\nthe largest is:" << large;
 cout << "\nthe aver is: " << ave;
 cout << "\n\nDone. Bye\n";
 return 0;
}

//funtion that read 10 numbeer to an array
void readNum(int data[])
{
  cout << "Input 10 integers: ";
  for(int i=0; i<10; i++)
       cin >> data[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 aver.
float aver(const int data[])
{
 int sum = 0;
  for(int i = 0;i < 10; i++)
    sum+= data[i];  
    return sum/10.0;
} 

Stv3n404 - 2023