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;)

Onlineshade commented: Try some code. +0

Recommended Answers

All 8 Replies

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.)

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.
It your task. Please give some effort on logic making.
Thank you.

techy23,
Try some code yourself.Anuradha Mandal is right.The logic is same as the pyramid printing. Try something .Then we will discuss more.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.