In this quick article, how to draw patterns in a C# console application, especially triangle patterns, like upward. We will use nested “for loops” to print our desired pattern.
Sample Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PatternProgram
{
class Program
{
static void Main(string[] args)
{
int val = 5;
int i, j, k ;
for (i = 1; i <= val; i++)
{
for (j = 1; j <= val-i; j++)
{
// Console.Write("");
}
for (k = 1; k <= i; k++)
{
Console.Write("*");
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}