In this session, we will see how to Print Pyramid Pattern in C#. This is mostly asked interview question for the beginner.

Pyramid Pattern of Number in C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PyramidPattern
{
 class Program
 {
 static void Main(string[] args)
 {
 int iRows = 6, iSpace, iNumber;
 Console.WriteLine("Pyramid Pattern");
 for (int i = 1; i <= iRows; i++) // Total number of rows for pramid 
 {
 for (iSpace = 1; iSpace <= (iRows - i); iSpace++) // Loop For Space 
 Console.Write(" ");
 for (iNumber = 1; iNumber <= i; iNumber++) //increase the value 
 Console.Write(iNumber);
 for (iNumber = (i - 1); iNumber >= 1; iNumber--) //decrease the value 
 Console.Write(iNumber);
 Console.WriteLine();
 }
 Console.ReadKey();
 }
 }
}

Output:

Pyramid Pattern

Pyramid Pattern of the asterisk in C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PyramidPattern
{
 class Program
 {
 static void Main(string[] args)
 {
 int iRows = 6, iSpace, iNumber;
 Console.WriteLine("Pyramid Pattern");
 for (int i = 1; i <= iRows; i++) // Total number of rows for pramid 
 {
 for (iSpace = 1; iSpace <= (iRows - i); iSpace++) // Loop For Space 
 Console.Write(" ");
 for (iNumber = 1; iNumber <= i; iNumber++) //increase the value 
 Console.Write("*");
 for (iNumber = (i - 1); iNumber >= 1; iNumber--) //decrease the value 
 Console.Write("*");
 Console.WriteLine();
 }
 Console.ReadKey();
 }
 }
}

Output:

Pyramid Pattern

View More:

Conclusion:

I hope would love this session. Please don’t hesitate to comment for any technical help. Your feedback and suggestion would be appreciated.

Thank You.

Leave a Comment