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 12 years experience in development life cycle in windows, service and Web based application using Microsoft.Net technologies. Proven record of developing all phases of projects in Microsoft.Net technology from initiation to closure aligning with the company's Business objectives to drive process improvements, competitive advantage and bottom-line gains. -> Good exposure of independently working and developing multiple projects ->Committed to efficient and effective development of projects in a fast-paced and deadline driver environment. Skill :- Develop and design projects in various technologies of Microsoft Technology. Total IT Experience- 13+

Previous Post Next Post

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