66 999
Assignments Done
99,2%
Successfully Done
In November 2018

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.

*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions