C# program to print below number triangle by entering no of lines
1
22
333
4444
55555
Here's a C# program that prints the number triangle based on the number of lines entered by the user:
using System;
class Program
{
static void Main()
{
Console.Write("Enter the number of lines: ");
int numLines = Convert.ToInt32(Console.ReadLine());
PrintNumberTriangle(numLines);
}
static void PrintNumberTriangle(int numLines)
{
for (int i = 1; i <= numLines; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write(i);
}
Console.WriteLine();
}
}
}
Below is the output of the above program:
In this program, the user is prompted to enter the number of lines. The PrintNumberTriangle method takes the number of lines as an argument and prints the number triangle accordingly. The inner loop is responsible for printing the current line number i repeatedly, based on the line number. Each line consists of the repetition of the line number, forming a triangle shape.