L
L
LamerToExpert12019-02-10 15:07:18
C++ / C#
LamerToExpert1, 2019-02-10 15:07:18

How to iterate over a matrix and compare its elements?

There is a code

#include <iostream>
using namespace std;
int comparare (int x , int y, int z) {
    int Max ;
    if(x > y && x > z) Max = x;
    if(y > x && y > z) Max = y;
    if(z > x && z > y) Max = z; 
    cout << "\n  - " << "x =  " << x << " y =  " << y << " z = "<< z << endl;
}
int main()
{
    const unsigned int DIM1 = 5;
const unsigned int DIM2 = 5;
int one, two, three, j  , n = 4;

int ary[DIM1][DIM2] = {
    { 1, 0, 0, 0, 0,},
    { 2, 4, 0, 0, 0},
    { 3, 6, 9, 0, 0},
    { 2, 7, 6, 8, 0 },
    { 2, 7, 6, 8, 0 }
};

for (int test = 0 ; test < (n-1) ; test ++) {

    for (int i = test ; i < (n-1) ; ) { 
       one = ary [i][i];       
    for ( j = i ; j < (i+1) ;j++ ) {
        two = ary [j+1][i];
     
    }
     i++;
    three= ary [i][j];
     comp (one,two,tree);
    }   
}           
}

The size of the matrix can be any, as long as it is a square matrix. Elements can also be different because they are entered from the keyboard or random
Next comes such an algorithm 5c601362162fd900431549.png
and so it is necessary to compare by 3 all elements of the matrix below the main dianonal.
Why is my code not working?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question