C# Program to print Star Triangle
In this C# program, we will take input (Number of rows) from the user and print the Star (*) triangle based on the Number of rows input by the user.
C# Program to print Star (*) Triangle Code:
private static void Main(string[] args)
{
int i, j, k, l, n;
char c = '*';
Console.Write("Enter the number of rows:");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n - i; j++)
{
Console.Write(" ");
}
for (k = 1; k <= i; k++)
{
Console.Write(c);
}
for (l = i - 1; l >= 1; l--)
{
Console.Write(c);
}
Console.Write("\n");
}
Console.ReadLine();
}
C# Program to print Star (*) Triangle Output:
