Feb 12, 2017 at 11:05pm UTC
I just posted around an hour ago for help with the orientation of my array, but now I need some suggestions/help trying to figure out how to print the 3 smallest and 3 largest values of my program. Here is my code
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
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main() {
srand(time(NULL));
int fun[3][3][3];
for ( int row=0; row<3; row++){
for (int column=0; column<3; column++){
for (int length=0; length<3; length++){
int x = rand() % 10;
fun[row][column][length] = x;
}
}
}
for (int column=0; column<3; column++){
for ( int row=0; row<3; row++){
for (int length=0; length<3; length++){
cout << fun[row][column][length] << " " ;
} cout << " " ;
} cout << endl;
} cout << endl;
}
Once run, I would get this
8 3 7 7 6 7 0 0 2
0 8 5 0 9 8 7 1 0
0 2 5 5 8 1 1 5 7
Now I need to print the smallest and largest 3 values which would be:
smallest: 0, 0, 0
largest: 8, 8, 9
Last edited on Feb 12, 2017 at 11:06pm UTC
Feb 15, 2017 at 11:26pm UTC
@gunnerfunner
How do you output the vector? also when I run this it outputs all the numbers instead of the largest 3 and smallest 3.