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.
*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
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!
Learn more about our help with Assignments:
C#