C# program to print the right half star pyramid pattern
Program.cs
int i, j;
for (i = 1; i <= 10; i++)
{
    for (j = 1; j <= i; j++)
    {
        Console.Write("*");
    }
    Console.Write("\n");
}
Output
kodingwindow@kw:~/csharp$ dotnet run
*
**
***
****
*****
******
*******
********
*********
**********
kodingwindow@kw:~/csharp$ 
C# program to print the left half star pyramid pattern
Program.cs
int i, j;
for (i = 1; i <= 10; i++)
{
    for (j = 1; j <= 10 - i; j++)
    {
        Console.Write(" ");
    }
    for (j = 1; j <= i; j++)
    {
        Console.Write("*");
    }
    Console.Write("\n");
}
Output
kodingwindow@kw:~/csharp$ dotnet run
         *
        **
       ***
      ****
     *****
    ******
   *******
  ********
 *********
**********
kodingwindow@kw:~/csharp$ 
C# program to print the inverted right half star pyramid pattern
Program.cs
int i, j;
for (i = 10; i >= 1; i--)
{
    for (j = 1; j <= i; j++)
    {
        Console.Write("*");
    }
    Console.Write("\n");
}
Output
kodingwindow@kw:~/csharp$ dotnet run
**********
*********
********
*******
******
*****
****
***
**
*
kodingwindow@kw:~/csharp$ 
C# program to print the inverted left half star pyramid pattern
Program.cs
int i, j;
for (i = 10; i >= 1; i--)
{
    for (j = 1; j <= 10 - i; j++)
    {
        Console.Write(" ");
    }
    for (j = 1; j <= i; j++)
    {
        Console.Write("*");
    }
    Console.Write("\n");
}
Output
kodingwindow@kw:~/csharp$ dotnet run
**********
 *********
  ********
   *******
    ******
     *****
      ****
       ***
        **
         *
kodingwindow@kw:~/csharp$ 
Advertisement