Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Display Hollow Inverted Pyramid pattern in C++ language

Posted on December 17, 2019December 17, 2019

Table of Contents

  • Display Hollow Inverted Pyramid pattern in C++ language
    • C++  inverted pyramid pattern – using for loop
    • C++  inverted pyramid pattern – using the while loop
    • C++  inverted pyramid pattern – using do-while loop

Display Hollow Inverted Pyramid pattern in C++ language

In this article, we will discuss the Display Hollow Inverted Pyramid pattern in C++ language – using loops

In this post, we will learn how to create hollow Pyramid  pattern using for, while and do-wile loop

C++  inverted pyramid pattern – using for loop

Program 1

This program allows the user to enter the number of rows and the symbol then the program displays a Hollow pyramid star pattern with the given symbol using for loop in C++ language

Program 1

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int i,j,rows;//declared variables
    char ch;
    cout<<"Enter number of rows\n";
    cin>>rows;
    //Takes number of rows from user
    cout<<"Enter the symbol\n";
    cin>>ch;
    //input symbol for pattern
    for(i=1; i<=rows; i++){//to iterates each row
for(j=1; j<=i; j++){//Print space for Pyramid shape
cout<<" "; //print space
}
for(j=1; j<=(rows*2-(2*i-1)); j++){//to print *
if(i==1 || j==1|| j==(rows*2-(2*i-1))){

 cout<<ch; //print star
  }
 else {
cout<<" "; //print space
 }

}
cout<<"\n";
}
getch();
    return 0;
}

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

Display Hollow Inverted Pyramid pattern in C++ language
Output

C++  inverted pyramid pattern – using the while loop

Program 2

This program allows the user to enter the number of rows and the symbol then the program displays a Hollow pyramid star pattern with the given symbol using while loop in C++ language

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int i,j,rows;//declared variables
    char ch;
    cout<<"Enter number of rows\n";
    cin>>rows;
    //Takes number of rows from user
    cout<<"Enter the symbol\n";
    cin>>ch;
    //input symbol for pattern
    i=1;
    while(i<=rows){//to iterates each row
            j=1;
while(j<=i){//Print space for Pyramid shape
cout<<" "; //print space
j++;
}
j=1;
while( j<=(rows*2-(2*i-1))){//to print *
if(i==1 || j==1|| j==(rows*2-(2*i-1))){

 cout<<ch; //print star
  }
 else {
cout<<" "; //print space
 }
 j++;
}
cout<<"\n";
 i++;
}
getch();
    return 0;
}

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

Display Hollow Inverted Pyramid pattern in C++ language
Ouyput

 

C++  inverted pyramid pattern – using do-while loop

Program 3

This program allows the user to enter the number of rows and the symbol then the program displays a Hollow pyramid star pattern with the given symbol using do-while loop in C++ language

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int i,j,rows;//declared variables
    char ch;
    cout<<"Enter number of rows\n";
    cin>>rows;
    //Takes number of rows from user
    cout<<"Enter the symbol\n";
    cin>>ch;
    //input symbol for pattern
    i=1;
    do{//to iterates each row
            j=1;
do{//Print space for Pyramid shape
cout<<" "; //print space
j++;
}while(j<=i);
j=1;
do{//to print *
if(i==1 || j==1|| j==(rows*2-(2*i-1))){

 cout<<ch; //print star
  }
 else {
cout<<" "; //print space
 }
 j++;
}while( j<=(rows*2-(2*i-1)));
cout<<"\n";
 i++;
}while(i<=rows);
getch();
    return 0;
}

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

Display Hollow Inverted Pyramid pattern in C++ language
Output

Suggested for you

for loop in C++ language

while loop in C++ language

do-while loop in C++ language

 

Similar post

pyramid pattern program in C- using loops

Java pyramid pattern program – using loops

C++ pyramid pattern program – using loops

C++ code to Inverted Pyramid pattern

Java code to Inverted Pyramid pattern

C code to Inverted Pyramid pattern

C language Hollow Pyramid pattern

Java language Hollow Pyramid pattern

Display Hollow Inverted Pyramid pattern in C language

Display Hollow Inverted Pyramid pattern in Java language

 

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes