CSharp · Console
using System;
public class TriangleProgram
{
public static void Main()
{
Console.WriteLine("Program for displaying pattern of *.");
Console.Write("Enter the maximum number of * line:");
int n = Convert.ToInt32(Console.ReadLine());
//for loop to work until i = n
for (int i = 1; i <= n; i++)
{
//for loop to add space
for (int j = 1; j <= (n - i); j++)
{
Console.Write(" ");
}
//for loop to print *, for each line
//k < i *2
//so for example, if i =1, it will print star for 1 times, as loop will work until k < 2, that is 1 time
// when i = 2, condition will be k < 4, means it will print star for 3 times
// and so on.
for (int k = 1; k < i * 2; k++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
}