Pyramid pattern program in C++

In this section you will learn how to print pyramid pattern in c++ in easy way. We will print the pyramid pattern with help of for loop condition and then we will show the output on screen. In this program we are taking the input from user.

How program will work?

Program of print pyramid pattern in c++


	#include<iostream.h>
	#include<conio.h>

	//PYRAMID PATTERN PROGRAM
	void main()
	{
   	   int value, i, j, k;
	   clrscr();
	   
	   cout<<"PROGRAM FOR DISPLAYING PYRAMID PATTERN OF *.";
	   cout<<"\nENTER NUMBER TO PRINT THE PYRAMID:- ";
	   cin>>value;
	   
	   for(i=1; i<=value; i++)
	   {
	   	for(j=0; j<=(value-i); j++)
		{
		    cout<<" ";
		}
		
		for(j=1; j<=i; j++)
		{
		    cout<<"*";
		}
		for(k=1; k<i; k++)
		{
		   cout<<"*";
		}
		cout<<"\n";
	   }
	   	   
	   getch();
	 }

Output:


	PROGRAM FOR DISPLAYING PYRAMID PATTERN OF *.
	ENTER NUMBER TO PRINT THE PYRAMID:- 5
	
            *
          * * *
        * * * * *
      * * * * * * *
    * * * * * * * * *

Post Your Comment