Can you help me with my code, please? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you help me with my code, please?

My program finds columns in a two-dimensional array that have elements equal to the maximum in the array. The program displays a list of elements of each such column. I want every column display 1 time.But if the maximum element occurs twice in one column, it displays the column twice. What to do? Моя программа находит в двумерном массиве столбцы, в которых есть элементы, равные максимальному в массиве. Программа выводит список элементов каждого такого столбца. Я хочу, чтобы каждый такой столбец она выводила 1 раз.Но если в одном столбце два раза встречается максимальный элемент, то она и выводит столбец два раза. Что делать? https://code.sololearn.com/ch44WFBV2MkE/?ref=app

17th Dec 2018, 1:34 PM
Иван
3 Answers
+ 2
Line 23, after your if statement finishes the for loop displaying the column, add a break statement to stop checking that column for another match.
18th Dec 2018, 1:08 AM
John Wells
John Wells - avatar
+ 2
Updated line: if ( x[n][m]==b_max) { for (int n=0; n<N; n++ ) { cout<<x [n][m]<<' '; } break; } break is used to abort a loop statement. for (int i=0;i<5;i++) break; stops the loop with i=0.
18th Dec 2018, 6:13 PM
John Wells
John Wells - avatar
+ 1
Thanks, but what is it break statement?
18th Dec 2018, 6:09 PM
Иван