C++ Program to Print Inverted Star Pyramid

Write a C++ Program to Print Inverted Star Pyramid with an example. This program allows us to enter the rows and the symbol to print in the inverted pyramid pattern. Next, the nested for loops will iterate between total rows and 1 to print the * (or given symbol). Here, if k != (2 * i – 1) condition is true, print * otherwise, C++ print empty space.

#include<iostream>
using namespace std;

int main()
{
	int i, j, k, rows;
	char ch;
	
	cout << "\nPlease Enter Inverted Pyramid Star Pattern Rows    =  ";
	cin >> rows;
	
	cout << "\nPlease Enter Any Symbol to Print  =  ";
	cin >> ch;	
		
	cout << "\n-----Inverted Pyramid Star Pattern-----\n";
	for ( i = rows ; i >= 1; i-- )  
	{
		for ( j = 0 ; j <= rows - i; j++ ) 
		{
      		cout << " ";   	
		}
			
		for(k = 0; k != (2 * i - 1); k++)
		{
			cout << ch;
			
		}
		cout << "\n";
	}

 	return 0;
}
C++ Program to Print Inverted Star Pyramid

C++ Program to Print Inverted Star Pyramid using a While Loop

#include<iostream>
using namespace std;

int main()
{
	int i, j, k, rows;
	char ch;
	
	cout << "\nPlease Enter Inverted Pyramid Star Pattern Rows    =  ";
	cin >> rows;
	
	cout << "\nPlease Enter Any Symbol to Print  =  ";
	cin >> ch;	
		
	cout << "\n-----Inverted Pyramid Star Pattern-----\n";
	i = rows ; 
	while(i >= 1 )  
	{
		j = 0 ; 
		while( j <= rows - i) 
		{
      		cout << " ";
      		j++ ;
		}
		
		k = 0;
		while (k != (2 * i - 1))
		{
			cout << ch;
			k++;
		}
		cout << "\n";
		i--;
	}

 	return 0;
}
Please Enter Inverted Pyramid Star Pattern Rows    =  9

Please Enter Any Symbol to Print  =  #

-----Inverted Pyramid Star Pattern-----
 #################
  ###############
   #############
    ###########
     #########
      #######
       #####
        ###
         #