Categories: category

Display integrated pyramid star pattern in C++ using while loop

Display integrated pyramid star pattern in C++ using while loop

In this tutorial, we will discuss a concept of  Display integrated pyramid star pattern in C++ using while loop

In C++ 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 double pyramid star pattern  using while loop in C++ language

integrated pyramid star pattern in C++

integrated pyramid Star pattern 1

Program 1

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

int main()
{
    int i,j,rows;
    cout<<"Enter the number of rows for pattern: ";
    cin>>rows;   //get input from the user for number of rows
    i=1;
while(i<=rows){  
    j=i;
    while(j<=rows){    //Print upper part of pattern
        cout<<"*";
        j++;
    }
    i++;
    cout<<"\n";
}

i=rows-1;
while(i>=1){
    j=i;
    while(j<=rows){
        cout<<"*";
        j++;
    }
    i--;
    cout<<"\n";
}
getch();
    return 0;
}

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

pyramid star pattern 1

 

Program 2

integrated pyramid Star pattern 2

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int i,j,row;
    cout<<"Enter the number of rows for pattern :";
    cin>>row;   //get input from the user for number of rows
    i=1;
while(i<=row){  
    j=1;
while(j<i){     //Print upper part of pattern
    cout<<" ";
    j++;
}
j=i;
    while(j<=row){
        cout<<"*";
        j++;
    }
    i++;
    cout<<"\n";
}

i=row-1;
while(i>=1){
    j=1;
while(j<i){
    cout<<" ";
    j++;
}
j=i;
    while(j<=row){
        cout<<"*";
        j++;
    }
    i--;
    cout<<"\n";
}
 getch();
    return 0;

}

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

pyramid star pattern 2

 

 

Program 3

integrated pyramid Star pattern 3

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

int main()
{
    int i,j,row;
    cout<<"Enter the number of rows for pattern: ";
    cin>>row;    //get input from the user for number of rows
    i=1;
while(i<=row){   
    j=1;
while(j<=i){     //Print upper part of pattern
    cout<<" ";
    j++;
}
j=i;
    while(j<=row){
        cout<<"*"<<" ";
        j++;
    }
    i++;
    cout<<"\n";
}

i=row-1;
while(i>=1){
    j=1;
while(j<=i){
    cout<<" ";
    j++;
}
j=i;
    while(j<=row){
        cout<<"*"<<" ";
        j++;
    }
    i--;
    cout<<"\n";
}
getch();
    return 0;
}

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

pyramid star pattern 3

 

Program 4

integrated pyramid Star pattern 4

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int i,j,row;
    cout<<"Enter number of rows to display pattern: ";
    cin>>row;    //get input from the user for number of rows
    i=1;
while(i<=row){   
    j=1;
while(j<=row-i){  //Print upper part of pattern
    cout<<" ";
    j++;
}
j=1;
    while(j<=i){
        cout<<"*";
        cout<<" ";
        j++;
    }
    i++;
    cout<<"\n";
}

i=1;
while(i<=row-1){
    j=1;
while(j<=i){
    cout<<" ";
    j++;
}
j=1;
    while(j<=row-i){
        cout<<"*";
        cout<<" ";
        j++;
    }
    i++;
    cout<<"\n";
}
getch();
    return 0;
}

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

pyramid star pattern 4

 

Program 5

integrated pyramid Star pattern 5

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

int main()
{
    int i,j,k,rows;
    cout<<"Enter the number of rows to display pattern: ";
    cin>>rows;     //get input from the user for number of rows
    i=1;
while(i<=rows){      
  for(j=1; j<=i; j++){ //Print upper part of pattern
  cout<<"*";

}

j=i*2;
while(j<rows*2){
  cout<<" ";
   j++;
}

k=i;
while( k>=1){
  cout<<"*";
   k--;
}

  cout<<"\n";

   i++;

}
getch();
    return 0;
}

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

pyramid star pattern 5

 

Program 6

integrated pyramid Star pattern 6

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

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

    i=rows;
while(i>=1){  //parent while loop
    j=rows;
  while(j>=1+rows-i){    //Print upper part of pattern
  cout<<"*";
   j--;

}
     j=i*2;
    while(j<rows*2-1){
  cout<<" ";
  j++;

    }

    k=1+rows-i;
    while( k<=rows){
    if(k!=1)
  cout<<"*";
 k++;

   }

  cout<<"\n";
  i--;

}
getch();
    return 0;
}

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

pyramid star pattern 6

Similar post

Display integrated pyramid star pattern in C using while loop

Display integrated pyramid star pattern in Java using while loop

C code to print double pyramid star pattern

Java code to print double pyramid star pattern

C++ code to print double pyramid star pattern

 

Suggested for you

Data types in C++ language

Variable in C++ language

While loop in C++ language

Nested while loop in C++ language

 

Find product of two numbers using recursion in Python
C program to find product two numbers using pointer
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