Skip to content
Advertisement

Printing pattern without importing modules

Please help me print the pattern below as it is, if the input entered is 7:

JavaScript

I figured out to find the middle element of the pattern with any input:

JavaScript

Please help me complete the above pattern…… Thanks in advance!

Advertisement

Answer

If you use a list-of-lists to store the values, the value for any specific cell can be determined by doing some basic math involving the cell indexes and the number of rows.

An illustration:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement