Sara Molavi Sara Molavi - 1 month ago 9
C# Question

printing matrix square shape c#

I have an 8*8 matrix and here is my code:

static void Main(string[] args)
{
const int matrix_rows = 8;
const int matrix_columns = 8;
double[,] matrix = new double[matrix_rows, matrix_columns];
for (int i = 0 ; i < matrix_rows ; i++)
{
for (int j = 0; j < matrix_columns; j++)
{

Console.WriteLine(matrix[i, j]+ "\t");

}
Console.WriteLine("\n");
}
Console.ReadKey();


I want it to be printed square shape but it prints one "0" in each line. what should I do?

Answer

You write a new line each time. Do Console.Write() instead of Console.WriteLine()

Comments