D
D
DartNyan2016-02-07 18:49:57
C++ / C#
DartNyan, 2016-02-07 18:49:57

What is wrong with my check for the maximum element in the array?

Hello.
I solve a university problem.
Apparently by the end he was too tired and the brain refuses to work.
I find the maximum element of the matrix among the ordered rows (it is obvious that such elements are the last in such rows), stuff them (max elements of only such rows) into a special array, and already in this array I look for the maximum. This is where the problem arose. (in the end)

spoiler
#include <stdio.h>
#include <stdlib.h>
#define n 3 //стобцы
#define m 4 //строки

void main()
{
    //Дана числовая матрица m x n.
    //Определить максимальный среди всех элементов тех строк, которые упорядочены по возрастанию

    enum BOOLEAN { false, true }; // 0 и 1
    int flag, max;
    int array[m][n] = { {1,2,3}, // +
                        {6,5,4}, // -
                        {7,8,9}, // +
                        {4,5,1} }; // -
    int forMax[m]; // Массив хранения максимальных результатов

    for (int j = 0; j < m; j++) { // Цикл перебора строк
        for (int i = 1; i < n; i++) { //Цикл проверки строки на упорядоченность
            if (array[j][i] > array[j][i-1]) {
                flag = true; //Пока условие выполняется flag = trute
            } else {
                flag = false; //Условие не выполнилось - проверка заканчивается
                break;
            };
        }
        if (flag == true)
                forMax[j] = array[j][n-1];
        else
            forMax[j] = 0;
    }

    max = forMax[0]; // Проблема
    for (int i = 1; i++; i < m) //m = 4
        if (max < forMax[i])
            max = forMax[i];

    printf("%i %i %i %i",forMax[0], forMax[1], forMax[2], forMax[3]);
    printf("\n%i", max);

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maaGames, 2016-02-07
@DartNyan

for (int i = 1; i++; i < m)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question