Pattern doublesidedarrow

i have half done this question . i am unable to thing about the next idea, please tell me how to continue!

Hello,
You are printing a triangle and you have to print double sided arrow.

Your logic/approach is not printing the desired .
Try to implement the following:

  1. an outer loop for each row.
    a) for upper n/2 rows:
    …i) logic for left side space
    …ii) logic for printing left side digits
    …iii) logic for inner space
    …iv) logic fro right digits
    b) for remaining lower rows:
    …i) logic for left side space
    …ii) logic for printing left side digits
    …iii) logic for inner space
    …iv) logic fro right digits
    c) change row

Always look for the flow to print pattern
Hope, this would help.
if you still have doubts, let me know.
But try this yourself first.

1 Like

i am unable to get logic for inner space. could u please help in that

declare s=2*(n/2)-1;
if outer loop iterates for i=0 to n

  1. for upper n/2+1 rows i.e till middle row,
    loop for inner space will iterate for j=0 to j<(2*i-1)
    when i=0, no space
    i=1, 1 space
    i=2, 3 spaces
    i=3, 5 spaces

  2. for lower half rows,
    first decrement s by 2, then
    loop inner space for j=0 to j<s
    i=4, 3 spaces
    i=5, 1 space
    i=6, 0 spaces

Hope, this would help.

1 Like