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:

#include<iostream>
#include<conio.h>
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: 

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++!

Out-Put:

Pyramid Shape Output

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

Previous PHP Tutorial 1: How to Create a Local Host
Next Firsts Day to Web Design: How to start Web Designing?

About author

Bahonar Javid
Bahonar Javid 43 posts

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

View all posts by this author →

You might also like