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());
int numOfSpaces = (size - 1) / 2;
int numOfNumberSignes = 1;
int numOfLines = (numOfSpaces * 2) + 1;
int midddleOfRhombus = ((size - 1) / 2) + 1;
for (int i = 1; i < numOfLines + 1; i++)
{
if (i < midddleOfRhombus)
{
for(int j = numOfSpaces; j > 0; j--)
{
Console.Write(" ");
}
numOfSpaces--;
for(int j = 0; j < numOfNumberSignes; j++)
{
Console.Write("#");
}
numOfNumberSignes += 2;
Console.WriteLine();
}
if (i == midddleOfRhombus)
{
for (int j = 0; j < size; j++)
Console.Write("#");
Console.WriteLine();
}
if (i > midddleOfRhombus)
{
numOfSpaces++;
for(int j = numOfSpaces; j > 0; j--)
{
Console.Write(" ");
}
numOfNumberSignes -= 2;
for(int j = 0; j < numOfNumberSignes; j++)
{
Console.Write("#");
}
Console.WriteLine();
}
}
}
}
}
Can anyone please help me to solve it?