Please help me with star patterns or anything with a patterns like 'x' in C++. What ois the logic behind it.

x x ********
xx xx *******
xxx xxx *****
xxxx xxxx ***
xxxxx xxxxx **

these might look easy, but i dont get the logic. please give detailed explanation, with simple example, if you can;)

Try some code.
5
Contributors
8
Replies
12
Views
7 Years
Discussion Span

You require a loop, complete answers will not be given without attempts

Here is a simple pseudo-code which represents the logic of the problem; no guarantees are given as to it's correctness.

``````for x in range(0, 10):
for y in range(0, 10):
if x >= y:
print("X", end='')
else:
print("*", end='')
print("\n")``````

(OK, so it isn't so pseudo a code, but it should be clear enough, I think. It also doesn't exactly match the described results, but it is close enough to give the OP a head start.)

Edited by Schol-R-LEA: n/a

Do you have tried any code?If so , post it.

Have you done any code printing a pyramid like....
x
xx
xxx
xxxx
xxxxx
..........

The logic is same as the pyramid printing.

You will need two for loops ..... one is for row and the other is for column.Try something to put some effort on creating logic.

For the sample one....
x
xx
xxx
xxxx
xxxxx
.........
the logic is...

``````for(i=1;i<=5;i++)//for 5 lines
for(j=1;j<i;j++)//for printing the x
cout<<"x";
cout<<endl;``````

Now you have to try your actual problem.