Hello, I’m working on this task:
Write a program that draws a rhombus using ASCII art and a ‘#’ sign. Every row should contain an odd number of signs, starting from one. Read from the console the size of the longest row of the rhombus. Call the variable size and declare it with var. It is guaranteed to be an odd number to make your rhombus look nice. (Note that all unused space to the left and right of the rhombus should be filled with spaces.)
Example 1:
>3
#
#
Example 2:
>5
#
###
###
#
Here is my code:
namespace Exam
{
class Rhombus
{
static void Main()
{
var size=int.Parse(Console.ReadLine());
char[] sizeArray= new char[size];
var middleNumber= sizeArray.Length/2;
var keepGoing=true;
var k=0;
while(keepGoing==true)
{
if(k==middleNumber)
{
for (var i=0; i<sizeArray.Length; i++)
if(sizeArray[i]==middleNumber)
sizeArray[middleNumber]='#';
else
{
sizeArray[middleNumber-k]=' ';
sizeArray[middleNumber+k]=' ';
}
Console.WriteLine(sizeArray);
k=k-1;
if(k==0)
keepGoing=false;
}
else
{
for (var i=0; i<sizeArray.Length; i++)
{
if(sizeArray[i]==middleNumber)
sizeArray[middleNumber]='#';
else
{
sizeArray[i]=' ';
sizeArray[middleNumber-k]='#';
sizeArray[middleNumber+k]='#';
}
}
Console.WriteLine(sizeArray);
k=k+1;
}
}
}
}
}
Can anyone please help me to solve it?