I do not know how to fill the other side and I think there is a better way to solve this problem, or the entire matrix.If you can please paste code.
Get this far for now:
1.Done.
2.What is the condition for checking the diagonal elements.
Could you write me some code with comments of steps that you do...i'll be so grateful!
For each row
output (
for each column
if column == row output row
else output 0
output )
EDIT:
What is the condition for checking the diagonal elements
With a square that would mean that the column and row are the same.
Could you write me some code with comments of steps that you do...i'll be so grateful!
I tried to give you pseudo code without giving you code. Since giving pseudo code was pretty much the answer anyways. Though as keskiverto mentioned you can use ? : (ternary operator) instead of if/else
The alternative solution would be:
1 2 3
assign all values to 0 --you can use default initialization with int arrays by assign {} or {0}.
for each row (column and row will be same in a square)
assign array[row][column] the row
I think it's good and much simple than the last one.
Thank you so much: giblit and keskiverto!!!!
You really helped me to understand this...thanks again.
The second one is very similar to the first algorithm I mentioned. The second one would look like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
int main()
{
std::size_t const size = 10u; //size = rows and columns (since it is a square)
int matrix[size][size] = {}; //initialize all to 0
for(int row = 0; row < size; ++row) //row and column will be same since diagonal
{
matrix[row][row] = row;
}
//output if you want
return 0;
}