pyramid triangle

C++ program to print combined Pyramid pattern

C++ program to print combined Pyramid Pattern

In this tutorial, we will discuss a concept of  the C++ program to print  Combined Pyramid pattern

In the C++ programming language, we can use for loop ,while loop and do-while loop to display different number (binary, decimal), alphabets or star pattern programs.

In this article, we are going to learn  how to Display combined Pyramid pattern  using for loop  in C++ language

Program to display combined Pyramid star pattern

Combined Pyramid star pattern 1

Program 1

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

int main()
{
    int i,j,rows;
    cout << "Ennter the number of rows" << endl;
    cin>>rows;//Takes input from the user
    cout<<"\n";
    for(i=1; i<=rows; i++){
  for(j=i; j<=rows; j++){
  cout<<" ";  //print space
  }
  for(j=1; j<=2*i-1; j++){
  cout<<"*";    //print star
  }
   for(j=2*i; j<=2*rows-1; j++){
  cout<<" ";    //print space
   }
  for(j=1; j<=2*i-1; j++){
  cout<<"*";   //print star
  }
  cout<<"\n";//move to next line

}
getch();
    return 0;
}

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

ointed Pyramid pattern 1

The C++ program allows the user to enter the number of rows then it displays two combined straight pyramid star pattern according to the number of rows.

Combined Pyramid star pattern 2

Program 2

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

int main()
{
    int i,j,rows;
    cout << "Ennter the number of rows" << endl;
    cin>>rows; //Takes input from the user
    cout<<"\n";

    for(i=1; i<=rows; i++){
  for(j=1; j<i; j++){
  cout<<" ";//print space
  }
  for(j=1; j<2*(rows-i+1); j++){
  cout<<"*";    //print star
  }
   for(j=2; j<2*i; j++){
  cout<<" ";//print space
   }
  for(j=1; j<2*(rows-i+1); j++){
  cout<<"*";  //print star
  }
  cout<<"\n";

}
getch();
    return 0;
}

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

Jointed Pyramid pattern 2

The C++ program allows the user to enter the number of rows then it displays two combined upside-down pyramid star pattern according to the number of rows.

 

Program to the combined Pyramid number pattern

Combined Pyramid number pattern 1

Program 1

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

int main()
{
    int i,j,rows;
    cout << "Ennter the number of rows" << endl;
    cin>>rows;  //Takes input from the user
    cout<<"\n";
    for(i=1; i<=rows; i++){
  for(j=i; j<=rows; j++){
  cout<<" ";//print space
  }
  for(j=1; j<=2*i-1; j++){
  cout<<j;
  }
   for(j=2*i; j<=2*rows-1; j++){
  cout<<" ";//print space
   }
  for(j=1; j<=2*i-1; j++){
  cout<<j;  //print number
  }
  cout<<"\n";

}
getch();
    return 0;
}

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

jointed Pyramid pattern 3

The C++ program allows the user to enter the number of rows then it displays two combined straight pyramid number pattern according to the number of rows.

 

Combined Pyramid number pattern 2

Program 2

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

int main()
{
    int i,j,rows;
    cout << "Ennter the number of rows" << endl;
    cin>>rows;  //Takes input from the user
    cout<<"\n";

    for(i=1; i<=rows; i++){
  for(j=1; j<i; j++){
  cout<<" ";//print space
  }
  for(j=1; j<2*(rows-i+1); j++){
  cout<<j;  //print number
  }
   for(j=2; j<2*i; j++){
  cout<<" ";//print space
   }
  for(j=1; j<2*(rows-i+1); j++){
  cout<<j;  //print number
  }
  cout<<"\n";

}
getch();
    return 0;
}

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

jointed Pyramid pattern 4

The C++ program allows the user to enter the number of rows then it displays two combined upside-down pyramid number pattern according to the number of rows.

 

Similar post

Java program to print combined Pyramid pattern

C program to print combined Pyramid pattern

C++ program to print combined Pyramid pattern

 

Suggested for you

For loop in C++ language

Nested for loop in C++ language

Operator n C++ language

Data types in C++ language

Variable in C++ language

 

 

Java program to print combined Pyramid pattern
Java program to create combined Pyramid pattern using while loop
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

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago