Answer to Question #17278 in C# for sandhya sharma

Question #17278
Write a program that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single space or a single newline character.

*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
1
Expert's answer
2012-10-26T10:06:04-0400
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;




namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

for (int i = 4; i >= -4; i--)

{

int absVal = Math.Abs(i);




PrintSpace(1);

PrintSpace(absVal);

PrintStar(1 + (4 - absVal) * 2);

Console.WriteLine();

}

Console.ReadKey();

}

static void PrintStar(int count)

{

for (int i = 0; i < count; i++)

{

Console.Write("*");

}

}

static void PrintSpace(int count)

{

for (int i = 0; i < count; i++)

{

Console.Write(" ");

}

}

}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS