# for Loop

 Islam Kamilov · April 1, 2015 Hello!I need a help to creating a star pattern with for loops... It should seems like if n=5;the output is:*************

## Replies

 Dol Lod · April 2, 2015 Split this into 2 for loops and one main body.For loop that goes from 1 to N, but not including N.Print out N starsFor loop that goes down from N up to 1 not including N. Islam Kamilov · April 2, 2015 Can you fix my program?/*The output is: Please Enter The Height Of The Pattern You Want:5**********//*  but I need the output is: if height is 5;**************/#include int main() {    int height;    printf("Please Enter The Height Of The Pattern You Want: \n");    scanf("%d", &height);        for (int row = 1; row<=height; row++) {                for (int col = 0; col (height-row)) {                printf(" ");            }            else {                printf("* ");            }        }        printf("\n");    }        return 0;} Dol Lod · April 2, 2015 I told you the general approach. I am not going to code this for you. Split this into two loops.Have the first loop print the first part in ascending order. ex. if height is 5, make it print *\n***\n,***\nThen have the second loop print in descending order. ex. if height is 5, make it print ***\n*\n.That's really all you need. If the height is even you were unclear about what you do. There is absolutely no reason to do this in one for loop instead of 2. Clark Alaan · April 12, 2015 Islam,The best way to learn programming is by doing it. It's been quite a while since this topic was posted but I just want to point out that there is a tutorial for this in Bucky's series for C. Tutorial 28 - How to make a table talks about nested for loops which is what Arjun is trying to tell you. Not trying to be rude, but I'm aiming to only state facts. Hopefully this is somewhat helpful. Islam Kamilov · April 16, 2015 Than you so much, Guys!!!
• 1

## C

129,969 followers