I am trying to write a program that reads from the console a positive integer N (N < 20) and prints a matrix like these ones:
N = 3
1 2 3
2 3 4
3 4 5
N = 5
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
This is my code:
using System;
namespace _6._12.Matrix
{
class Program
{
static void Main()
{
Console.WriteLine("Please enter N ( N < 20): ");
int N = int.Parse(Console.ReadLine());
int row;
int col;
for (row = 1; row <= N; row++)
{
for (col = row; col <= row + N - 1; )
{
Console.Write(col + " ");
col++;
}
Console.WriteLine(row);
}
Console.WriteLine();
}
}
}
The problem is that the console prints one extra column with the number from 1 to N and I dont know how to get rid of it. I have an idea why this might be happening but still can't find a solution.