Draw star pyramid using C#

Sample input: 5
Sample output:

code-01

Code:


/*Author: Md. Mahedee Hasan*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StarPyramid
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Enter a number to draw pyramid: “);
int nRow = 0;
nRow = Convert.ToInt32(Console.ReadLine());

for (int row = 1; row <= nRow; row++) { for (int leftSpace = row; leftSpace <= nRow; leftSpace++) { Console.Write(” “); } for (int star = 1; star <= 2 * row – 1; star++) { Console.Write(“*” + ” “); //Print star and space } Console.WriteLine(); } Console.ReadKey(); } } } [/csharp] [wpdm_file id=50]

Please share, if it is helpfulShare on FacebookShare on LinkedInTweet about this on TwitterShare on Google+Email this to someonePrint this page

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>