In this tutorial, we will discuss the Inverted Pyramid number pattern in Cpp language
In this topic, we will learn about how to create an Inverted Pyramid number pattern in C++ using for loop or nested for loop
Inverted Pyramid number pattern in Cpp language
Pattern 1
Pyramid pattern in C++
Inverted Pyramid number pattern program 1
#include
#include
using namespace std;
int main()
{
int i,j,k,rows,count1,temp,num;
cout<<"Enter the number of rows: ";
cin>>rows;//get input from user for number rows
cout<<"Here your pattern: \n";
count1=1;
temp=1+(rows-1)*2;
for(i=1; i<=rows; i++){
//parent for loop to iterates row
num=1;
for(j=1; j<=count1; j++){//print space in biginning
cout<<" ";
}
for(k=temp; k>=1; k--){
cout<
When the above code is compiled and executed, it produces the following results
Enter the number of rows: 5
Here your pattern:
123456789
1234567
12345
123
1
Pattern 2
Pyramid pattern in c++
Pyramid pattern program 2
#include
#include
using namespace std;
int main()
{
int i,j,k,rows;
int count1=1, num;
cout<<"Enter the number of rows: ";
cin>>rows;//get input from user for number of rows
cout<<"Here your pattern: \n";
count1=1;
num=1+(rows-1)*2;
for(i=1; i<=rows; i++){//outer for loop for iterate row
for(j=1; j<=count1; j++){//inner for loop to print space
cout<<" ";
}
for(k=num; k>=1; k--){//inner for loop for print number
cout<
When the above code is compiled and executed, it produces the following results
Enter the number of rows: 5
Here your pattern
111111111
2222222
33333
444
5
Pattern 3
Pyramid number pattern in C++
Pyramid pattern program 2
#include
#include
using namespace std;
int main()
{
int i,j,rows,space=0;
int count1=1, num;
cout<<"Enter the number of rows: ";
cin>>rows;//get input from user for pyramid
cout<<"Here your pattern: \n";
for(i=rows; i>=1; i--){//outer for loop for iterate row
for(j=1; j<=space; j++)//inner for loop to print space
cout<<" ";
for(j=1; j<=i; j++)//print right side of piramid
cout<=1; j--)//print right side of piramid
cout<
When the above code is compiled and executed, it produces the following results
Enter the number of rows: 6
Here your pattern:
12345654321
123454321
1234321
12321
121
1