Hacker Challenge: Printing a Star Pattern
Learn to create a star pattern using nested loops.
We'll cover the following
Printing a star using nested loops
In this lesson and in the next, we’ll try to think of two solutions to print the star pattern using nested loops. Further, we will discuss how to simplify our implementation. In the 2nd implementation, we’ll learn to avoid writing nested loops and use a helper function to print patterns.
Problem Statement
Write a program that takes height
(has to be a multiple of 4) as input from the user and prints a star, as shown below. The following shape is of height 12
:
*
***
*****
*****************
***************
*************
*************
***************
*****************
*****
***
*
Get hands-on with 1200+ tech skills courses.