Jump to content

How to print this pyramid pattern?


Go to solution Solved by polaryeti,

Recommended Posts

2004452992_pastedimage0.png.b48969f0fb30a1d8c6f13885ce939162.png

I want this pattern, what's the logic behind this one? There are lots of blogs online that show code but not teach technique. Share any blogs that you know that teach the logic behind it as well.

At i=1, j=5 should be printed as star, rest as white spaces

At i=2, j=4,6…

At i=3, j=3,5,7….

At i=4,j=2,4,6,8…

At i=5, j=1,3,5,7,9…

 

How do I convert this into logic?


 

Link to comment
https://forums.phpfreaks.com/topic/315617-how-to-print-this-pyramid-pattern/
Share on other sites

  • Solution

for (i = 1; i <= 5; i++) {
  for (space = 1; space <= 5 - i; space++) {
    document.write("0");
  }
  for (j = 1; j <= i; j++) {
    document.write("X0");
  }
  document.write("<br>");
}

 

I got help from tutorial video to solve this.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.