Hello. Can you help me out telling me how to print a 4x4 matrix? This is how the matrix should look
0 - - -
+ 0 - -
+ + 0 -
+ + + 0
I guess it is asking to make the code like if row>column then output +, if column>row output - and if row=column then output 0. Missed a few classes now im kinda confused.
for(int y = 0; y < 4; ++y) //Loop through the y locations
{
for(int x = 0; x < 4; ++x) //Loop through the x locations
{
if(x > y) //If the column is greater than the row
std::cout << "- ";
elseif(x == y) //If the column is equal to the row
std::cout << "0 ";
else //Else, if the row is greater than the column
std::cout << "+ ";
}
std::cout << std::endl; // Print a newline, advance to the next line
}
You use two loops to go through all x and y coordinates, then depending on the relation between the two, you print the right character.