C++ Program to Print Hollow Star Pyramid Pattern

Write a C++ program to print the hollow star pyramid pattern using for loop.

#include<iostream>
using namespace std;

int main()
{
	int i, j, k, rows;
     
    cout << "Enter Hollow Pyramid Star Pattern Row = ";
    cin >> rows;

    cout << "Hollow Pyramid Star Pattern\n"; 

    for(i = 1; i <= rows; i++)
    {
    	for(j = 1; j <= rows - i; j++)
		{
            cout << " ";
        }
        for(k = 1; k <= i * 2 - 1; k++)
        {
            if(k == 1 || k == i * 2 - 1 || i == rows)
            {
                cout << "*";
            }
            else
            {
                cout << " ";
            }
        }
        cout << "\n";
    }		
 	return 0;
}
C++ Program to Print Hollow Star Pyramid Pattern

This C++ example prints the hollow pyramid pattern of a given character using a while loop.

#include<iostream>
using namespace std;

int main()
{
	int i, j, k, rows;
    char ch;
     
    cout << "Enter Hollow Pyramid Star Pattern Row = ";
    cin >> rows;

    cout << "Enter Symbol for Hollow Pyramid Pattern = ";
    cin >> ch;

    cout << "Hollow Pyramid Star Pattern\n"; 

    for(i = 1; i <= rows; i++)
    {
    	for(j = 1; j <= rows - i; j++)
		{
            cout << " ";
        }
        for(k = 1; k <= i * 2 - 1; k++)
        {
            if(k == 1 || k == i * 2 - 1 || i == rows)
            {
                cout << ch;
            }
            else
            {
                cout << " ";
            }
        }
        cout << "\n";
    }		
 	return 0;
}
Enter Hollow Pyramid Star Pattern Row = 14
Enter Symbol for Hollow Pyramid Pattern = &
Hollow Pyramid Star Pattern
             &
            & &
           &   &
          &     &
         &       &
        &         &
       &           &
      &             &
     &               &
    &                 &
   &                   &
  &                     &
 &                       &
&&&&&&&&&&&&&&&&&&&&&&&&&&&

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.