In this tutorial, we will discuss Cpp program to Hollow Pyramid Pattern
In this topic, we will learn how to create hollow pyramid star pattern in C++ programming language
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 triangle pattern in C++ language
#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 inverted pyramid triangle pattern in C++ language
Suggested for you
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 Python language
If statements in Java language
Nested if statements in Java language
Floyd’s triangle number pattern using for loop in C
Floyd’s triangle pattern using nested for loop in Java
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…