Algorithm in C ++ to find greater odd value? [closed]

-2

Good, I am solving an exercise of the facu and it is a program that generates n matrices with pseudo-random values. I'm in this function:

  

2. Function "void imparmayor (...)": detects in the array "MInicio [] []" the largest odd value and its position: row and column "and stores it in an array     "mayorimpar [n] [3]".

Achievement generate n matrices of 10x10 random numbers, but I can not make an algorithm that finds the highest odd value of each, I can find separately the largest, and otherwise the odd but not together.

    
asked by Lautaro 23.01.2018 в 18:17
source

1 answer

0

At first you create a variable to assume that it is the largest

int mayor = Miinicio[0][0];

Then you go through the matrix with the help of two cycles for , from 0 to 10. And you perform this validation

if((Miinicio[i][j] % 2) == 0)
  if (Miinicio[i][j] > mayor)
    mayor = Miinicio[i][j];

In the end you will have the highest par value. To get the biggest odd you just change the == by! =

    
answered by 23.01.2018 / 20:50
source