Hacker Challenge: Palindromic Pyramids

Let's create different pyramid patterns using nested loops.

In this lesson, we will write a program that prints pyramids with numbers and alphabets. So let’s start a discussion on the pyramid of numbers!

Pyramid of numbers

Write and run a program that prints the following shape:

Height: 5
    1
   121
  12321
 1234321
123454321

Look at the above example for Height: 5, where we need to figure out the pattern in each line. Notice that the numbers are printed in ascending order and descending order from 1 to a number k.

  • In line 1, one number is printed.
  • In line 2, two numbers are printed in ascending order and one in descending order.
  • In line 3, three numbers are printed in ascending order and two in descending order.

Can you see a pattern based on the line number?

Get hands-on with 1200+ tech skills courses.