Hollow diamond pattern not working for n=7,9

please help me i always ran in to problem when i have to make lower part of patterns …
i struggle to find stopping conditions for loops such that it work for all value of N’s .
here is my code …please explain

it will be great help …

Hello @Diwyanshu,

In most of the patterns, the space in the upper half increases and then the reverse of that is followed in the lower half i.e. decrease in this case.
The no. of spaces in a particular row share a relationship with the previous row.

Let’s consider your code Hollow diamond pattern:
There are a few mistakes in that:

  1. In the lower half, you are printing the stars for each in the wrong order.
  2. In both the upper and the lower half you have missed printing " " i.e. whitespace.
    Solution:
    cout<<" "<<’\t’;
  3. The logic for space is also incorrect for the lower half.
    Solution:
    Iterate the for loop for the lower half in reverse order.
    This way you can apply the same logic that you have applied for the upper half.

Hope, this would help.