2. 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 minCols = 5;
    	int cols;

    	// Pieprasa ievadīt kolonnu skaitu, kam jābūt vismaz 5
    	do
    	{
        	Console.Write($"Ievadi kolonu skaitu, ne mazak ka {minCols}: ");
    	} while (!int.TryParse(Console.ReadLine(), out cols) || cols < minCols);

    	// Izvada pirmo tabulu (no labas uz kreiso)
    	for (int i = 1; i <= cols; i++)
    	{
        	PrintLine(i, cols);
        	PrintNumbers(i, cols);
    	}
    	PrintLine(cols, cols);


    	// Izvada otro tabulu (no kreisas uz labo - spoguļattēls)
    	for (int i = 1; i <= cols; i++)
    	{
        	PrintLineMirrored(i, cols);
        	PrintNumbersMirrored(i, cols);
    	}
    	PrintLineMirrored(cols, cols);
	}

	static void PrintLine(int row, int totalCols)
	{
    	int displayCols = Math.Min(row, totalCols);
    	int tabs = Math.Max(0, totalCols - displayCols);
    	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);
    	int tabs = Math.Max(0, totalCols - displayCols);
    	Console.Write(new string('\t', tabs));
    	Console.Write("|");
    	for (int i = row - displayCols + 1; i <= row; i++)
    	{
        	Console.Write($" {i} |");
    	}
    	Console.WriteLine();
	}

	static void PrintLineMirrored(int row, int totalCols)
	{
    	int displayCols = Math.Min(row, totalCols);
    	Console.Write("+");
    	for (int i = 0; i < displayCols; i++)
    	{
        	Console.Write("---+");
    	}
    	Console.WriteLine();
	}

	static void PrintNumbersMirrored(int row, int totalCols)
	{
    	int displayCols = Math.Min(row, totalCols);
    	Console.Write("|");
    	for (int i = 1; i <= displayCols; i++)
    	{
        	Console.Write($" {i} |");
    	}
    	Console.WriteLine();
	}
}

