1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
//Lab 3-2: Array with 10 elements with algorithm for computing average value,
//finding minimum value and showing corresponding index.
#include <iostream>
using namespace std;
//get function print into memory
double average(double firstarray[], int numofNums);
double minimum(double firstarray[], int numofNums);
int main()
{
double myarray[] = { 100, 27, 64, 55, 32, 73, 89, 14, 6, 44 };
const int numofNums = 10;
cout << "Average equals " << average(myarray, numofNums) << endl;
cout << "Minimum equals " << minimum(myarray, numofNums) << endl;
cin.get();
return 0;
}
double average(double myarray[], int numofNums){
double sum = myarray[0];
for (int i = 1; i < numofNums; i++) {
sum += myarray[i];
}
return sum / numofNums;
}
double minimum(double myarray[], int numofNums){
int min = 0;
for (int i = 1; i < numofNums; i++) {
if (myarray[min] > myarray[i]){
min = i;
}
}
return myarray[min];
}
|