1. uzdevums
Veidoja Ilgvars Līckrastiņš 04.03.2025
Vide: Programiz C# Online Compiler





using System;

class Program
{
	static void Main()
	{
    	Console.WriteLine("Mans vards: Ilgvars");
    	Console.WriteLine("Mans uzvards: Lickrastins");

    	int minRows = 5, minCols = 5;
    	int rows, cols;

    	// Pieprasa ievadit rindu skaitu, kam jabut vismaz 5
    	do
    	{
        	Console.Write($"Ievadi rindu skaitu, ne mazak ka {minRows}: ");
    	} while (!int.TryParse(Console.ReadLine(), out rows) || rows < minRows);

    	// Pieprasa ievadit kolonnu skaitu, kam jabut vismaz 5
    	do
    	{
        	Console.Write($"Ievadi kolonu skaitu, ne mazak ka {minCols}: ");
    	} while (!int.TryParse(Console.ReadLine(), out cols) || cols < minCols);

    	// Izvada tabulu rindu un kolonnu veida
    	for (int i = 1; i <= rows; i++)
    	{
        	PrintLine(i, cols);
        	PrintNumbers(i, cols);
    	}
    	PrintLine(rows, cols);
	}

	static void PrintLine(int row, int totalCols)
	{
    	int displayCols = Math.Min(row, totalCols); // Ierobezo kolonnu skaitu, lai neparsniegtu max
    	int tabs = Math.Max(0, totalCols - displayCols); // Izrekina nepieciesamo tabulas daudzumu
    	Console.Write(new string('\t', tabs));
    	Console.Write("+");
    	for (int i = 0; i < displayCols; i++)
    	{
        	Console.Write("---+");
    	}
    	Console.WriteLine();
	}

	static void PrintNumbers(int row, int totalCols)
	{
    	int displayCols = Math.Min(row, totalCols); // Nodrosina ka kolonnu skaits neparsniedz max
    	int tabs = Math.Max(0, totalCols - displayCols); // Izrekina tabulas daudzumu, lai nolidzinatu rindas
    	Console.Write(new string('\t', tabs));
    	Console.Write("|");
    	for (int i = row - displayCols + 1; i <= row; i++) // Ja kolonnas parsniedz robezu, izdzes pirmos skaitlus
    	{
        	Console.Write($" {i} |");
    	}
    	Console.WriteLine();
	}
}
