Pyramid Patterns in C++ with Examples

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

// Star Pyramid Program
#include<iostream>
#define clrscr() system("cls")
using namespace std;
int main()
{
        int n,m;
        int i,j,k;
        cout<<"\n Enter the limit of row";
        cin>>n;
        m=n;
          for(i=1;i<=n;i++)   
        {
               for(j=1;j<=m-1;j++)
               {
                  cout<<" ";
               }   
               for(k=1;k<=2*i-1;k++)      
              { 
                   cout<<"*";
              }    
           m--;        
          cout<<"\n";    
        }
         
       
}

Program 2

// Star Pyramid Program1
#include<iostream>
#define clrscr() system("cls")
using namespace std;
int main()
{
        int n,m;
        int i,j,k;
        cout<<"\n Enter the limit of row";
        cin>>n;
        m=n;
         for(i=n;i>=1;i--)              
         {
                for(j=1;j<m;j++)
                {
                     cout<<" ";
                }
                for(k=1;k<=2*i-1;k++)
               { 
                  cout<<"*";  
               }   
          m++;
           cout<<"\n"; 
         }    
}

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *