Javid Bahonar

How to make a full pyramid shape in C++?

How to make a full pyramid shape in C++?

We are supposed to draw a pyramid shape using a source code in C++. It is important to know that the pyramid shape we are going to draw by the code is a 2D pyramid, which is exactly the same as a triangle shape in geometry.

In order to make a full pyramid shape in C++ you need to have the following knowledge at first.

  • You should be able to use C++ as a basic user.
  • You should be able to read comments between the lines of the source code.
  • You should be able to use loops (specially for loop which is used in this example)

Let’s start making our 2D pyramid shape or the geometric triangle!

Steps to Code a Full Pyramid Shape in C++:

Step One:

Create a new C++ file in your IDE and include your library functions and the main function in order to start the program; which are:

using namespace std;
int main ()

Step Two:

Declare you variable which are needed to draw the pyramid and write a line of code to ask about the number of lines you would like to draw the pyramid.

Example: I would like to draw an eight row pyramid; so I would declare the number of lines as 8.

See Also: [button link=”http://codejow.com/php-tutorial-1-how-to-create-a-local-host/” target=”self” color=”blue” icon=”none” style=”normal” size=”default”]How To Create Local Host Using PHP?[/button]

Step Three:

You need to use three different for loops for the following purposes:

The first for loop keeps the record of the number of lines.
The second for loop draws the spaces required for the start of the lines.
The third for loop draws the shape (in this code we have chosen * as our shape) for each line.

Step Four:

Compile your source code and run the code to get the required shape.

Further explanations will be provided in the comment lines in the source code.

Write a program to draw a full pyramid shape in C++!


Pyramid Shape Output

Feel free to ask any sort of questions in the comment below.

Javid Bahonar
Bahonar Javid

* Computer Application Student * Co-Founder of www.codejow.com * Love to code and Learn new languages * Enjoy playing football

Related Posts
%d bloggers like this: