Hey Guys 🙂 , today i am going to tell you the tricks to make star pattern like pyramids. Suppose we have to make pattern like

*
**
***
****

So here are the steps to make pattern like this as;

Step 1: count the depth or number of levels in a pattern as we can see here depth of pymarid = 4

Step 2:  Make a table like

Row number Number of stars
1 1
2 2
3 3
4 4

Step 3: So depth will be our used in our first loop.

Step 4: And you see in table the no of star = row number. so second loop goes for number of star times.

 

Program:

#include <stdio.h>
int main()
{
 int depth, inc1, inc2;
 
 printf("Enter level of pyramid");
 scanf("%d", &depth);
 
 for(inc1 = 0; inc1 < depth; inc1++){
    for(inc2 = 0; inc2 <= inc1 ; inc2++){
        printf("*");
    }
 printf("\n");
 }

return 0;
}

Output:

 

Hope you guys enjoy and learn something new 🙂 . If you guys want me write about any specific topic, Please let me know, you can write it in comment box. I am happy to help.

 

Leave a Reply

Your email address will not be published. Required fields are marked *