Tutorial to make Star Patterns

Tutorial to make Star Patterns
Here, first we have to understand how these patterns are printed.
Let’s take an example of simple triangle,

First we have to find the relation between values of ‘i‘ and star (j),
i=1 -> j=1
i=2 -> j=3
i=3 -> j=5
i=4 -> j=7
After observing above conditions, we have the relation j=2*i-1.

Now for whitespaces…
We have the number of rows i.e. n=4, here in the example…


i=1  ->  j=3

i=2  ->  j=2

i=3  ->  j=1

i=4  ->  j=0

i.e. relation is j=n-i


So now, we have got the relation for both the star and whitespaces.

Now the last step is to put these relations in for loop in given below Algorithm.


1. Number of rows  n=4.

2. Repeat steps 3 to 11 for i=1,2,3,…….,n.


3.        j=n-i.

4.       Repeat steps 5 to 6, while j>0.


5.             Print ‘_’ (whitespace).

6.                j–


7.        j=2*i-1.

8.       Repeat steps 9 and 10 while j<0.


9.             Print ‘*’.

10.               j–


11.      Print ‘new line’.


12.       END.

Like this we can find more relations for different patterns by just changing the value of ‘j ‘and number of for loops, rest of the programs remains almost same…

Author Description


Our mission is to bring the affordable Technology education to people everywhere, in order to help them achieve their dreams and change the world. - Follow @program_guide

No comments yet.

Join the Conversation