C# program to print below star triangle by entering no of lines
*
***
*****
*******
Here's the C# program that prints the star triangle with spaces 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());
for (int i = 1; i <= numLines; i++)
{
// Print spaces
for (int j = 1; j <= numLines - i; j++)
{
Console.Write(" ");
}
// Print stars
for (int k = 1; k <= 2 * i - 1; k++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
}
This program prompts the user to enter the number of lines, then it uses nested loops to print the star triangle with spaces. The outer loop controls the number of lines. The first inner loop prints the appropriate number of spaces before the stars on each line, based on the line number and the total number of lines. The second inner loop prints the stars for each line, with the number of stars being '2 * i - 1' (where i is the current line number).