I always get 5 7 7 but should get the maximum numbers from each column. Please correct my code.
#include<ctime>
#include<iostream>
#include <cstdlib>
using namespace std;
int main()
{
const int ROWS{ 3 };
const int COLS{ 3 };
int col = 0, row = 0;
int matrix2[ROWS][COLS];
Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.
You can use the preview button at the bottom to see how it looks.
You need to seed your random number generator with an initial call to srand().
You have multiple variables called row and col. Which is asking for trouble.
You are quite a long way from finding the maximum in each column: for that the column loop would need to be the outer loop and you would need to reset 'max' at the start of each new column. Also, calling a variable 'max' runs the risk of clashing with the standard library function of the same name.