Pyramid in Console Application

Pyramid in Console Application provides code example to build pyramid in console application using c#. There are two code example for pyramid, the second example for reverse pyramid.

reverse pyramid in c#

Pyramid in Console Application


Pyramid Example

  class Program  
   {  
     static void Main(string[] args)  
     {  
       Console.Write("Enter the Level of pyramid :");  
                  
       int level = Convert.ToInt32(Console.ReadLine());  
                  
       for (int i = 1; i <= level; i++)  
       {  
         for (int j = 1; j <= level - i; j++)  
         {  
           Console.Write(" ");  
         }  
         for (int j = 1; j <= 2 * i - 1; j++)  
         {  
           Console.Write("*");  
         }  
         Console.WriteLine(" ");  
       }  
   
         
       Console.Read();  
     }  
   }  

Reverse Pyramid Example

  class Program  
   {  
     static void Main(string[] args)  
     {  
       Console.Write("Enter the Level of pyramid :");  
       int level = Convert.ToInt32(Console.ReadLine());  
         
       int x = 0, y = 0;  
   
       for (x = 1; x <= level; ++x)  
       {  
         // Print spaces  
         for (y = 1; y <= x; ++y)  
         {  
           Console.Write(" ");  
         }  
         // Print star/  
         for (y = 1; y <= ((level * 2) - ((2 * x) - 1)); ++y)  
         {  
           Console.Write("*");  
         }  
         // Print new line  
         Console.WriteLine(" ");  
       }  
   
       Console.Read();  
     }  
   }  

Summary

Here in the above example, we saw how to write program to print pyramid and reverse pyramid. I hope you have enjoyed a lot.

Thanks

Kailash Chandra Behera

An IT professional with over 13 years of experience in the full software development life cycle for Windows, services, and web-based applications using Microsoft .NET technologies. Demonstrated expertise in delivering all phases of project development—from initiation to closure—while aligning with business objectives to drive process improvements, competitive advantage, and measurable bottom-line gains. Proven ability to work independently and manage multiple projects successfully. Committed to the efficient and effective development of projects in fast-paced, deadline-driven environments. Skills: Proficient in designing and developing applications using various Microsoft technologies. Total IT Experience: 13+ years

Previous Post Next Post

نموذج الاتصال