Challenge 3: Printing Pyramid
Test your understanding of loops by printing a half pyramid for a given number of rows in this lesson.
We'll cover the following
Problem statement
Write code which prints half a pyramid of the alphabet a.
- The code takes an integer variable
$rows
as input and prints the pyramid with that number of rows displayinga
.
Hint: Use
for
loops to implement the solution.
Input
An integer.
Output
Print the character a
on the console.
Sample input
$rows
is equal to 5.
Sample output
Note: In order to move values to next line you can use
\n
.
Coding challenge
Write your code below. It is recommended that you try solving the exercise yourself before viewing the solution.
Good Luck!
#the $rows variable contains the number of rows that you need to print#write the code for making and printing the pyramid here#use can use \n to move numers to next line in the pyramid#use " " to add space between numbers in pyramidprint"\n"; #comment out this line when you start writing code