Wednesday, May 18, 2011

Different Patterns in CPP & C - Part 1

Hi there.
I thought that I should start archiving it online what I learnt at the CPP Training centre. So, one of the problem they gave me was to draw this pattern.

     *
    ***
   *****
 *********
***********

So, if you look carefully, the above triangle can be shown as:


After analyzing this pattern, you can see that it will need 3 for loops.
First for drawing the spaces, second for drawing the stars as triangle and the third one to draw the other side of triangle.