Console Application for creating star pyramid using C# code

Google+ Pinterest LinkedIn Tumblr +

// Console Application for creating star pyramid using C# code

// For value of 4

//               *

//              * *

//             * * *

//            * * * *

using System;

namespace STAR

{

class Class1

{

static void Main()

{

   Console.WriteLine(“Enter the value “);

int k=int.Parse(Console.ReadLine());

int n=k-1;

int x=2*(k-1)+1;

for(int p=0;p<=n;p++)

{

for(int j=k-1;j>=0;j–)

{

Console.Write(” “);

}

for(int i=0;i<=(x-2*(k-1));i++)

{

if(i%2==1)

{

Console.Write(“*”);

}

else

{

Console.Write(” “);

}

}

Console.WriteLine();

k–;

   }

Console.ReadLine();

}

}

}

Share.

About Author

Leave A Reply