pyramid triangle

Cpp program to Hollow Pyramid Pattern

Cpp program to Hollow Pyramid Pattern

In this tutorial, we will  discuss the concept of Cpp program to Hollow Pyramid Pattern

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

Hollow Pyramid pattern

Program 1

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

int main()
{
    int rows;
    cout << "Enter the rows for hollow pyramid" << endl;
    cin>>rows;
    for(int i=1; i<=rows; i++){//do print each rows
        for(int j=i; j<=rows; j++){ //print space for pyramid
        cout<<" ";
    }
    for(int k=1; k<2*i; k++){
            if(i==rows || (k==1 || k==2*i-1)){
                cout<<"*";
            }
            else{
                cout<<" ";
            }


    }
    cout<<"\n"; //move to next line
    }
    getch();
    return 0;
}

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

Hollow Pyramid pattern 1

 

Hollow pyramid triangle pattern in C++ language

 

Hollow Inverted Pyramid pattern

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

int main()
{
    int rows;
    cout << "Enter the rows for hollow pyramid" << endl;
    cin>>rows;
    for(int i=rows; i>=1; i--){//do print each rows
        for(int j=rows; j>i; j--){ //print space for pyramid
        cout<<" ";
    }
    for(int k=1; k<2*i; k++){
            if(i==rows || (k==1 || k==2*i-1)){
                cout<<"*";
            }
            else{
                cout<<" ";
            }


    }
    cout<<"\n";//move to next line
    }
    getch();
    return 0;
}

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

Hollow Pyramid pattern 2

 

 

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

 

 

Suggested for you

Loops in Java language

Loops in C language

Loops in C++ language

 

For loop in C++ language

For loop in Java language

For loop in C language

For 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

 

If statements in Java  language

Nested if statements in Java  language

 

 

Cpp program to Floyd's triangle star pattern
Java code to Hollow Pyramid 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