Number pattern

Inverted Pyramid number pattern in Cpp language

Inverted Pyramid number pattern in Cpp language

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 <iostream>
#include <conio.h>
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<<num;//print number for pattern
            num++;
        }
        count1++;
        temp=temp-2;
        cout<<"\n";
    }
    getch();
    return 0;
}

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++

Inverted Pyramid number pattern program 2

#include <iostream>
#include <conio.h>
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<<i;
        }
        count1++;
        num=num-2;
        cout<<"\n";
    }
    getch();
    return 0;
}

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++

Inverted Pyramid number pattern program 2

#include <iostream>
#include <conio.h>
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<<j;
        for(j=i-1; j>=1; j--)//print right side of piramid
            cout<<j;
            cout<<"\n";
            space++;
    }
    getch();
    return 0;
}

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

 

Suggested for you

for loop in C++ language

Nested for loop in C++language

Operator in C++ language

Data type in  C++ language

 

Cpp program to pyramid number pattern
triangle number pattern using nested while in C
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago