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 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include <iostream>
#define NUM_ROW 4
#define NUM_COLUMN 4
#define NUM_DEPTH 3
using namespace std;
/* 1. The minimum and maximum values among all the array elements*/
float minMax(float Value[NUM_ROW][NUM_COLUMN][NUM_DEPTH], float &minValue, float &maxValue)
{
minValue = Value[0][0][0];
maxValue = Value[0][0][0];
for (int i = 0; i < 4, i++;)
for (int j = 0; j < 4, j++;)
for (int k = 0; k < 3, k++;)
{
if (minValue < Value[i][j][k])
{
minValue = Value[i][j][k];
}
else if (maxValue > Value[i][j][k])
{
maxValue = Value[i][j][k];
}
}
cout << minValue << endl;
cout << maxValue << endl;
return 0.0;
}
/*2. The average values of all array elements*/
/*3. The location (i, j, k) of the element that
has the maximum value difference with its neighboring elements (1 point).
Here (i, j, k) refers to the array indices of the element. */
int main(){
float a, b;
float Value[NUM_ROW][NUM_COLUMN][NUM_DEPTH] =
{ 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2,
2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2,
3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2,
4.1, 4.2, 4.3, 4.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2
};
minMax(Value, a, b);
system("pause");
return 0;
}
|