star pattern

Cpp program to display Pyramid star pattern

Cpp program to display Pyramid star pattern

In this tutorial, we will discuss about Cpp program to display Pyramid star pattern

In this topic, we will learn how to create Pyramid star pyramid pattern in C++ language using nested for loop

 

Star Pyramid pattern 1

Star pyramid pattern

Program 1

Pyramid pattern

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

int main()
{
    int rows;
    cout << "Enter the number of rows" << endl;
    cin>>rows;
    for(int i=1; i<=rows;  i++){//outer for loop
            for(int j=1; j<=(rows-i)*2; j++){
                cout<<" ";//print space fot pyramid
            }
            for(int k=i; k>=1; k--){//inner for loop
                cout<<" "<<"*";  //create left half
            }
            for(int l=2; l<=i; l++){
                 cout<<" "<<"*" ; //create right half
            }
 cout<<"\n";
    }
     getch();
    return 0;
}

 

Enter the number of rows
6      
            *
          ***
        *****
      *******
    *********
  ***********

 

Star Pyramid pattern 2

Inverted star Pyramid

Program 2

Inverted Pyramid pattern

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

int main()
{
    int rows;
    cout << "Enter the number of rows" << endl;
    cin>>rows;
    for(int i=rows; i>=1;  i--){//outer for loop
            for(int j=i; j<=rows; j++){
                cout<<" ";//print space fot pyramid
            }
            for(int j=1; j<=(2*i-1); j++){//inner for loop
                cout<<"*";  //print star
            }
 cout<<"\n";//move to next line
    }
     getch();
    return 0;
}

 

Enter the number of rows
6
***********
  *********
    *******
      *****
        ***
          *

 

 

Star Pyramid pattern 3

Right leaned star pyramid pattern

Program 3

Right leaned Pyramid pattern

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

int main()
{
    int rows;
    cout << "Enter the number of rows" << endl;
    cin>>rows;
    for(int i=1; i<=rows;  i++){//outer for loop
            for(int j=1; j<=i; j++){//inner for loop 
                cout<<"*";//print star fot pyramid top half
            }
             cout<<"\n";  //move to next line
    }
            for(int i=rows; i>=1; i--){//outer for loop
            for(int j=1; j<=i; j++){//inner loop
                 cout<<"*" ; //print star for bottom half
            }
 cout<<"\n";
    }
     getch();
    return 0;
}

 

Enter the number of rows
6
*
**
***
****
*****
******
*****
****
***
**
*

 

Star Pyramid pattern 4

Left leaned pyramid triangle

Program 4

Left leaned Pyramid pattern

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

int main()
{
    int rows;
    cout << "Enter the number of rows" << endl;
    cin>>rows;
    for(int i=1; i<=rows;  i++){//outer for loop
            for(int j=i; j<rows; j++){
                cout<<" ";//print space for pyramid
            }
            for(int j=1; j<=i; j++){
                    cout<<"*";//print star for pyramid top part
                    }//inner for loop
                     cout<<"\n";
    }

            for(int i=rows; i>=1;  i--){//outer for loop
            for(int j=i; j<=rows; j++){
                cout<<" ";//print space for pyramid
            }
            for(int j=1; j<i; j++){
                    cout<<"*";//print star for pyramid below part
                    }//inner for loop
                     cout<<"\n";
    }
     getch();
    return 0;
}

 

 

  Enter the number of rows 
6      
         *
       **
     ***
   ****
 *****
******
  *****  
    ****
      ***
        **
          *

 

Similar Post 

Floyd’s triangle number pattern using for loop in C

Floyd’s triangle pattern using nested for loop in Java

Floyd’s triangle pattern using nested while loop in Java

Hollow pyramid triangle pattern in C++ language

Pyramid star pattern in Cpp

Pyramid star pattern in C

Pyramid star pattern in Java 

Rhombus pattern in Java using for loop

Rhombus pattern in C using while loop

Rhombus pattern in C++ using do-while loop

Display Pyramid star pattern in C

Display Pyramid star pattern  in Java

 

Suggested for you

For loop in C++ language

For loop in Java language

For loop in C language

For loop in Python language

while loop in C++ language

while loop in Java language

while loop in C language

while loop in Python language

Nested for loop in Java language

Nested for loop in C++ language

Nested for loop in C language

Nested for loop in Python language

Java code to Hollow Pyramid Pattern
C program to display pyramid star 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

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