C++ Program to Print Pyramid Star Pattern

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

#include<iostream>
using namespace std;

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

    cout << "Pyramid Star Pattern\n"; 

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

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

#include<iostream>
using namespace std;

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

    cout << "Enter Symbol = ";
    cin >> ch;


    while(i <= rows)
    {
        j = 0; 
    	while(j <= rows - i)
		{
            cout << " ";
            j++;
        }
        k = 0; 
        while(k < i * 2 - 1)
        {
            cout << ch;
            k++;
        }
        cout << "\n";
        i++;
    }		
 	return 0;
}
Enter Row = 18
Enter Symbol = $

                  $
                 $$$
                $$$$$
               $$$$$$$
              $$$$$$$$$
             $$$$$$$$$$$
            $$$$$$$$$$$$$
           $$$$$$$$$$$$$$$
          $$$$$$$$$$$$$$$$$
         $$$$$$$$$$$$$$$$$$$
        $$$$$$$$$$$$$$$$$$$$$
       $$$$$$$$$$$$$$$$$$$$$$$
      $$$$$$$$$$$$$$$$$$$$$$$$$
     $$$$$$$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$
   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

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.