pyramid triangle

program to display Double pyramid number pattern in C++

program to display Double pyramid number pattern in C++

In this tutorial, we will discuss the concept of the program to display Double pyramid number pattern in C++

In this post, we will learn how to create  double (integrated)pyramid number patterns in C++ programming language.

We can use for loop, while loop or do while loop to display different integrated pyramid number patterns.

 

Here, we will use for loop to print different integrated pyramid number patterns

Program 1

Integrated pyramid number pattern 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int rows,i,j;
    cout << "Enter the number of rows: "<< endl;
    cin>>rows;                 //takes input from the user
    for(i=1; i<=rows; i++){    //print upper part
    for(j=i; j<=rows; j++){
      cout << j;//print number for upper part
}
cout << "\n";//move to next line
}

for(i=rows-1; i>=1; i--){  //print lower part
    for(j=i; j<=rows; j++){
      cout << j;//print number for lower part
}
cout << "\n";//move to next line
        }
        getch();
    return 0;
}

 

When the above code is executed, it produces the following result

Enter the number of rows: 6
123456
23456
3456
456
56
6
56
456
3456
23456
123456

 

Program 2

Integrated pyramid number pattern 2

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int rows,i,j;
    cout<<"Enter the number of rows: ";
    cin>>rows;//take input from user
    for(i=rows; i>=0; i--){    //print upper part
    for(j=1; j<=i; j++){
      cout<<j;//print number for upper part
      cout<<" ";
}
cout<<"\n";//move to next line
}
for(i=1; i<=rows; i++){  //print lower part
    for(j=1; j<=i; j++){
      cout<<j;//print number for lower part
      cout<<" ";
}
cout<<"\n";//move to next line
        }
    return 0;
}

 

When the above code is executed, it produces the following result

Enter the number of rows
6
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3
1 2
1
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6

 

 

Program 3

Integrated pyramid number pattern 3

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int rows,i,j,k;
    cout<<"Enter the number of rows\n";
    cin>>rows;
    for(i=1; i<=rows; i++){    //print upper part
    for(j=1; j<=i; j++){
       cout<<" ";//print space
}
for(k=i; k<=rows; k++){
       cout<<k;//print number for upper part
       cout<<" ";
}
 cout<<"\n";//move to next line
}

for(i=rows-1; i>=1; i--){  //print lower part
    for(j=1; j<=i; j++){
       cout<<" ";//print space
}
for(k=i; k<=rows; k++){
       cout<<k;//print number for lower part
       cout<<" ";
}
 cout<<"\n";//move to next line

}
getch();
return 0;
}

When the above code is executed, it produces the following result

Enter the number of rows: 6
1   2   3   4   5   6
  2   3   4   5   6
    3   4   5   6
      4   5   6
        5   6
          6
        5   6
      4   5   6
    3   4   5   6
  2   3   4   5   6
1   2   3   4   5   6

 

Program 4

Integrated pyramid number pattern 4

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int rows,i,j;
    cout<<"Enter the number of rows: ";
    cin>>rows;
    for(i=1; i<=rows; i++){    //print upper part
    for(j=1; j<i; j++){
      cout<<" ";//print space
}
for(j=i; j<=rows; j++){
      cout<<j;//print number for upper part
}
cout<<"\n";
}

for(i=rows-1; i>=1; i--){
  for(j=1; j<i; j++){
      cout<<" ";//print space
}

for(j=i; j<=rows; j++){  //print lower part
      cout<<j;//print number for lower part
}
cout<<"\n";
        }
getch();
    return 0;
}

 

When the above code is executed, it produces the following result

Enter the number of roes: 6
123456
  23456
    3456
      456
        56
          6
        56
      456
    3456
  23456
123456

 

Program 5

Integrated pyramid number pattern 5

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int rows,i,j,k;
    cout<<"Enter the number of rows: ";
    cin>>rows;
    for(i=1; i<=rows; i++){    //print upper part
    for(j=1; j<=rows-i; j++){
      cout<<" ";
}
for(k=1; k<=i; k++){
      cout<<k;//print number for upper part
     cout<<" ";
}
cout<<"\n";
}

for(i=1; i<=rows-1; i++){  //print lower part
    for(j=1; j<=i; j++){
      cout<<" ";
}
for(k=1; k<=rows-i; k++){
      cout<<k;//print number for lower part
      cout<<" ";
}
cout<<"\n";
        }
        getch();
    return 0;
}

 

When the above code is executed, it produces the following result

Enter the number of rows: 6
         1
       1  2
     1  2  3
   1  2  3  4
  1  2  3  4  5
1  2  3  4  5  6
  1  2  3  4  5
    1  2  3  4
      1  2  3 
        1  2
          1

Similar post

 Integrated pyramid number pattern in C

Integrated pyramid number pattern in Java

 

Suggested for you

Operator in C++ language

Data type in C++  language

variable in C++  language

For loop in C++ language

Nested for loop in C++ language

 

 

Generate Double pyramid number pattern in Java
C program to generate Double pyramid number pattern
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…

1 month 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