8 x 8 array, need assistance

Hows it going guys, I'm working on this 8x8 array that is filled with randoms numbers between 1 and 100, it has to search my matrix for the minimum and max values and print them and if the min and max occur more than once they have to print the occurrences of them. after the matrix has to be sorted into descending order and i need ti print the average value of the entire matrix.Also i need the matrix to be symmetrical. Could someone please help fix my program to do this. Here is what i have so far.:

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
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

void sort(int MyArray[8][8])
{
     for(int ir=0;ir<8;ir++)
     {
        for(int ic=0;ic<8;ic++)
        {
            for(int jr=0;jr<8;jr++)  
            {
                    for(int jc=0;jc<8;jc++)
                    {        
                if(MyArray[ir][jr]>MyArray[ic][jc])
                {
                    int temp=MyArray[ir][jr];
                    MyArray[ir][jr]=MyArray[ic][jc];
                    MyArray[ic][jc]=temp;
                    }
                }
            }
        }
    }
}
void print(int MyArray[8][8])
{
    for (int i=0; i<8; i++)
    {
        for (int j=0; j<8; j++)
        {
            cout<<MyArray[i][j]<<" ";
        }
        cout<<endl;
    }cout<<endl;
}

int main ()
{
    srand ((unsigned)time(0));
    int array[8][8];
    for (int i=0; i<8; i++)
    {
        for (int j=0; j<8; j++)
        {
            array[i][j]=rand()%(99) + 1; //fill the array with elements
        }
    }
    print (array);
    sort (array); //sort
    print(array); //print after sorting
    cout<<endl<<"The Maximum value in the matrix is "<<array[0][0];
    cout<<endl<<"The Minimum value in the matrix is "<<array[7][7]<<endl;
    cout<<endl;
    system ("pause");
    return 0;
}
Last edited on
Topic archived. No new replies allowed.