C++ Program to Print Pyramid Pattern

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

Program 1

//Program to print star Pyramid
// *****
// ****
// ***
//**
#include<iostream>
using namespace std;
int main()
{
       int i,j,n;
       system("cls");
       cout<<"\n Enter the limit";
       cin>>n;
       for(i=n;i>=1;i--)
       {
          for(j=1;j<=i;j++)
          {

              cout<<"*";
          }
          cout<<"\n";
       }
       return 0; 
}

Program 2

//Program to print star Pyramid
// 12345
// 1234
// 123
//12
//1
#include<iostream>
using namespace std;
int main()
{
       int i,j,n;
       system("cls");
       cout<<"\n Enter the limit";
       cin>>n;
       for(i=n;i>=1;i--)
       {
          for(j=1;j<=i;j++)
          {

              cout<<j;
          }
          cout<<"\n";
       }
       return 0; 
}

program 3

//Program to print star Pyramid
// ABCDE
// ABCD
// ABC
//AB
//A
#include<iostream>
using namespace std;
int main()
{
       int i,j,n;
       char ch;
       system("cls");
     xyz: cout<<"\n Enter the limit";
       cin>>n;
       if(n>26)
    {
        cout<<"\nPls Enter till 26";
        goto xyz;

    }
    else
    {
       for(i=n;i>=1;i--)
       {
           ch='A';
          for(j=1;j<=i;j++)
          {
              cout<<ch++;
          }
          cout<<"\n";
       }
    }
       return 0; 
}

Program 4

//Program to print star Pyramid
// 54321
// 5432
// 543
//54
//5
#include<iostream>
using namespace std;
int main()
{
    int i,j,n;
    
    system("cls");
    cout<<"Enter the limit";
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=n;j>=i;j--)
        {
            cout<<i;
        }
        cout<<"\n";
    }
    return 0;
}

Your opinion matters
Please write your valuable feedback about DataFlair on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

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