C++ program to print number in pyramid shape

This is once of the basic program to start programming in C++.Here your main goal is to print the number’s in pyramid shape.The size of the shape depends on the input of the user.The output is similar to this picture:

For this we need to write the control statements such as for loop.Here in the program we use the method print_pyramid to print the output.Now we shall write a program to this problem:

class pyramid
  int n;
  void print_pyramid();
void pyramid :: print_pyramid()
  for(int i=1;i<=n;i++)
     for(int j=1;j<=i;j++)
       cout<<j<<"  ";
void main()
   cout<<"Enter number  of lines to be printed in pyramid shape:";
   pyramid ob;

you can download the code:download


About Anuroop D

Very enthusiastic about technology and likes to share my knowledge through blogging. Has Bachelor's in Information Technology and currently pursuing my PhD in Computer Science.
This entry was posted in C++ and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s