What is Inverted and Hollow Inverted Half Pyramid Pattern?
(i) Inverted Half Pyramid
Program:
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter number of rows: ";
cin>>n;
for(int row=0;row<n;row++) //loop to change line
{
for(int col=0;col<n-row;col++) //loop to print *
{
cout<<"* ";
}
cout<<endl;
}
return 0;
}
Output:
*****
****
***
**
*
(ii) Hollow Inverted Half Pyramid
Program:
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter number of rows: ";
cin>>n;
for(int row=0;row<n;row++) //loop to change line
{
for(int col=0;col<n-row;col++) //loop to print *
{
if(row==0 || col==0|| col==n-row-1) //printing * at boundaries
cout<<"* ";
else
cout<<" ";
}
cout<<endl;
}
return 0;
}
Output:
*****
* *
* *
**
*
C++ program to print Inverted Half Pyramid and Hollow Inverted Half Pyramid Pattern
Reviewed by Beast Coder
on
February 09, 2021
Rating:
No comments: