I have a 5 x 5 matrix which I fill with random numbers that are between 1 and 9 but I would like the main diagonal of the matrix to be filled only with (-1)
I have a 5 x 5 matrix which I fill with random numbers that are between 1 and 9 but I would like the main diagonal of the matrix to be filled only with (-1)
You can try this way:
mat = new int[5,5];
Random rnd = new Random();
for(int f = 0; f < 5; f++)
{
for(int c = 0; c < 5; c++)
{
if(f == c){
mat[f, c] = -1;
}else{
mat[f, c] = rnd.Next(1, 10);
}
}
}