# Creating pyramid using C++



## jacy (Jul 19, 2004)

Hello,
I am trying to print a pyramid of height 8. Can someone please give me some hint. I am not getting the desired output. Thank you.

```
#include<iostream.h>
#include<iomanip.h>
void main()
{
  int n=8;


	 for (int row=1; row<=8; row++)
	 {
		  for (int col=0; col<row; col++)
		  {

				cout<<setw(n=n-1)<< '*';

		  }
		  cout << endl;  // end the line.
	 }

}
```


----------



## kidnewbie (Mar 8, 2006)

pyramids are 3d. i don't think you can print 3d objects on a console.

is this what you want:


```
*
      ***
     *****
    *******
   *********
  ***********
 *************
***************
```
if so, here's the code:


```
#include <iostream.h>

int main()
{
    for (int i = 1; i <= 8; i++)
    {
        for (int j = 8 - i; j >= 1; j--)  {cout << " ";}
        for (int j = 1; j <= i * 2 - 1; j++) {cout << "*";}
        cout << endl;
    }
    return 0;
}
```


----------



## jacy (Jul 19, 2004)

Yeah thats what i need, thanks a lot.


----------

