Complicated pyramid

hi guys, i have complicated homework to do. how do i print this pyramid using c++. i have been trying since last month but can't do it. any help please

1
2
3
4
5
6
7
8
9
10
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *

how complicated?
lol! very complicated. any help please?
Almost one month? O_o

Do you notice any patterns? Your shape is 9 characters wide, only that not all of the characters are asterisks in each line. On the first line, there's 1 asterisk and 8 spaces. On the next, there are 3 asterisks and 6 spaces. See? For each line (until line 5), the number of spaces to the left decreases by one, the number of asterisks increases by two, and the number of spaces to the right increases by one. After line 5, the opposite happens.

Think you could write that with a few for loops?

-Albatross
Last edited on
how are you guys doing it. i spend almost one month on it but can't figure out the concept
Er... I just rely on my intuition.

If you have troubles seeing patterns, then I'd suggest you just start solving problems that require you to see them, like this one. :)

-Albatross
Last edited on
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
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
using namespace std;

void main()
{
  int size,i,j;
  cout<<"\nEnter the size range: ";
  cin>>size;
  for(i=0;i<size;i++)
  {
	  for(j=i;j<size;j++)
	  {
		  cout<<" ";
	  }
	  for(j=0;j<i;j++)
	  {
		  cout<<"*";
	  }
	  for(j=0;j<i-1;j++)
	  {
		  cout<<"*";
	  }
	  cout<<"\n";
  }
  for(i=size;i<(2*size);i++)
  {
	  for(j=0;j<(i-size);j++)
	  {
		  cout<<" ";
	  }
	  for(j=(i-size);j<size;j++)
	  {
		  cout<<"*";
	  }
	  for(j=(i-size);j<(size-1);j++)
	  {
		  cout<<"*";
	  }
	  cout<<"\n";
  }
}
you are good
Bello Abdullahi Maimaje, in the future, I'd like to ask that you don't post solutions to problems, especially if they aren't well-commented, and especially if they don't feature the best coding style (void main()) There are a few good reasons not to. :/

-Albatross

EDIT: The answer to the ultimate question of life, the universe, and anything, now a palindrome, as my post count, which is still counting.
Last edited on
^lolwut? Someone reported you? I wonder who...
it was me that reported ALBATROSS because we are all here to learn, and no solution is perfect. He better learn how to speak next time. I asked because, it was complicated for me not asked anyone to dis respect anyone here.

I'm happy with BELLO ABDULLAHI MAIMAJE help because, i learn alot from his program.
Last edited on
it was me that reported ALBATROSS because we are all here to learn


Yes, but the problem is many people will simply take the solution and leave...you might do that, for example. I'd like to hope that you won't, but given you didn't even bother to make an effort makes me think otherwise.
Topic archived. No new replies allowed.