Number pattern

C++ program to create combined Pyramid pattern using while loop

C++ program to create combined Pyramid pattern using while loop

In this tutorial, we will discuss a concept of  the C++ program to create  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 while loop  in C++ language

Program to display combined Pyramid star pattern

Combined Pyramid star 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.

Program 1

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

int main()
{
    int i,j,rows;
    cout<<"Enter the number of rows: \n";
    cin>>rows;
    cout<<"\n";

    i=1;
while(i<=rows){  //parent while loop
    j=i;
  while(j<=rows){
   cout<<" ";//print space
  j++;
  }
  j=1;
  while( j<=2*i-1){
   cout<<"*";//print star
   j++;
  }
  j=2*i;
   while(j<=2*rows-1){
   cout<<" ";//print space
  j++;
   }
   j=1;
  while( j<=2*i-1){
   cout<<"*";//print star
  j++;
  }
   cout<<"\n";//move to next line
i++;
}
getch();
    return 0;
}

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

C++ program to create combined Pyramid pattern

 

Combined Pyramid star 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 2

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

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

    i=1;
while( i<=rows){//parent while loop
    j=1;
  while(j<i){
  cout<<" ";//print space
   j++;
  }
  j=1;
  while(j<2*(rows-i+1)){
  cout<<"*";//print star
   j++;
  }
  j=2;
   while(j<2*i){
  cout<<" ";
  j++;
   }
   j=1;
  while( j<2*(rows-i+1)){
  cout<<"*";//print star
   j++;
  }
  cout<<"\n";//move to next line
   i++;

}

getch();
    return 0;
}

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

C++ program to create combined Pyramid pattern

 

 

Program to display combined Pyramid number pattern

Combined Pyramid number pattern 1

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.

Program 1

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

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

    i=1;
while(i<=rows){  //parent while loop
    j=i;
  while(j<=rows){
   cout<<" ";//print space
  j++;
  }
  j=1;
  while( j<=2*i-1){
   cout<<j;//print number
  }
  j=2*i;
   while(j<=2*rows-1){
   cout<<" ";//print space
  j++;
   }
   j=1;
  while( j<=2*i-1){
   cout<<j;//print number
  j++;
  }
   cout<<"\n";//move to next line
i++;
}
getch();
    return 0;
}

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

C++ program to create combined Pyramid pattern

 

 

Combined Pyramid number pattern 2

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.

Program 2

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

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

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

}

getch();
    return 0;
}

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

C++ program to create combined Pyramid pattern

 

Similar post

Java program to print combined Pyramid pattern

C program to print combined Pyramid pattern

C++ program to print combined Pyramid pattern

C program to print combined Pyramid pattern using while loop

Java program to print combined Pyramid pattern using while loop

 

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 create combined Pyramid pattern using while loop
Program to display combined Pyramid pattern in C 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

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

2 days ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

5 days ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 week ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 weeks ago

C# inverted full pyramid star pattern

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

1 month ago

C# Full Pyramid star pattern program

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

2 months ago