Printing a pattern.

Can any1 help me print this pettern

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

I have to use loops i have the following code but the loop doesn't end for some reason.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <stdlib.h>

int main()

{

int i, j, y, x;

x = 4;
y = 7;

for (i = 0; i < x; i++)

{
	
		for (j = y; j > 0; j--2)

		printf ("*");
		
	        printf ("\n");

}


return (EXIT_SUCCESS);

}
line 17 shouldn't even compile
Also, this code prints a square. To print a triangle, you have to modify the value of y.
What should my code be?
The right syntax to decrement by one is j--, the right syntax to decrement by any other number is j-=2

the pseudocode would be
loop x times{
    print '*' y times
    print '\n'
    
    decrement y by two
}
j--2 Could this compile as
j - -2
(a.k.a. do nothing)?
It shouldn't, -- is a unary operator
The compiler will take the largest token, as determined during lexical analysis, according to the "maximum munch" principle.
Topic archived. No new replies allowed.