Hollow diamond pattern (pattern 6)

code : https://ide.codingblocks.com/s/208523

i am able for print for n=5… but how to print for 0<n<10??

@chaman9 the only fault i can see in your code is that while you are printing the * correctly, you have hard coded the spaces. So you should count the number of spaces being printed in between stars and print them using a loop as well.

@chaman9 now this code will work for only n = 5 no matter what because you need to change the number of rows according to n as well, for eg
for n = 3
***
* *
***
this should be printed. So the number of rows being printed is also n.

I printed it for n=5… where first and last row contains all the elements
but not able to get the logic how to print middle rows…

like it will be varying for n=3,5,7

@chaman9 you need to find a relationship between the number of stars in each row to the number of row, and similarly with spaces. for eg, for n = 5 in rows -

  1. the number of stars are n, the num of spaces is 0
  2. the number of stars are n/2 the number of spaces is n - 2*(n/2) and again n/2 stars are there
    similarly you have to find a relationship for all the n rows.
    (note that the number of characters printed each time cannot exceed n)

Now the first n/2 rows will be symmetrical to the last n/2 rows along the middle row. Similarly, the left part of the pattern is symmetrical to the right part.
You will need nested loops for this pattern.

okay i got your point… i will try thanks

@chaman9 please mark your doubt as resolved if you are satisfied.