Introduction

In this blog, I am going to discuss how to show pyramid by using loop in C#.
Algorithm
  1. Get no. of rows that can be shown in pyramid.
  2. Loop through no. of rows.
  3. Find the centre point and add star(*).
  4. Add 2 * more than previous row in every row.
Code:
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. int rows = 15;
  6. for (int i = 0; i < rows; i++)
  7. {
  8. for (int j = rows -i - 1; j > 0; j--)
  9. {
  10. Console.Write(" ");
  11. }
  12. for (int k = 0; k < (i +1)* 2 - 1; k++)
  13. {
  14. Console.Write("*");
  15. }
  16. Console.WriteLine();
  17. }
  18. Console.ReadLine();
  19. }
  20. }
Output