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()
{

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();
}
}
}
}
}

``````

Your romb looks really great! However, the system doesn’t accept your solution because spaces should be not only before `#`, but afterwards as well.
But I have a couple of suggestion to make your life while solving this task easier:

1. You could

introduce a flexible middle of the row:

``````int middleCount = Math.Abs(size / 2 - i);
``````

that would be recalculated on every row and decide what sign to print based on distance to this variable.

1. You need to fill every single cell of your dimensional array. The most popular way to do it is to use for in for, like:
``````for (int i = 0; i < length; i ++) {
for (int j = 0; j < hight, j++) {
// your calculations on what should be printed in cell with address myArray[i][j]
}
}
``````

p.s.: in this specific case `length = hight`

2 Likes

Yes. Now i see that i need to feeled unused spase with spaces. Thank you for answer and tips

You wold like to use more nesteded for loops?
I think that i understand what you want to do by logical, but for my hard to imagine it like a code.

1 Like
``````for (int i = 0; i < hight; i ++) {
for (int j = 0; j < length, j++) {
int middleCount = Math.Abs(length / 2 - i);

if ( distanse to middle count correct)
print #
else
print ' '
}
}
``````