nested looping in c

write a program that prints the following patterns

Use nested FOR loop to generate the patterns.

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

this is what i have where am i going wrong please correct.

#include <stdio.h>
#define SIZE 5

int main()
{
int i;

for (i = 1; i <=SIZE; i ++)

printf("*");

printf("\n");

getchar();
return 0;
}
First, you should ask questions properly. Beginning with "write a program that prints the following patterns" sounds like you're issuing orders, not asking for help.

Second, to do that, you need two for loops, as your title points out. The outer one should determine how far the inner one will go:

1
2
3
4
5
6
7
8
int i, j;

for(i = 0; i < SIZE; ++i) {
    for(j = 0; j <= i; ++j) {
        printf("*");
    }
    printf("\n");
}
Third, this is the most common homework problem posted on the forum. A simple search, here or even in Google, will yield example after example...

Try these keywords and see for yourself: pyramid, triangle, asterisk.
ok thanks so much. Sorry about how i asked the question but its how my lecturer gave me the question
Topic archived. No new replies allowed.