In this tutorial, we will discuss Triangle Hollow Pattern using nested while loop in Cpp
In this program, we are going to learn about how to display Hollow Tringle star pattern using nested while loop in C++ programming language
Here, we display an Hollow triangle Pattern program with coding using nested while loop and also program get input from the user using Cin function in C++ programming language
The user can provide numbers as they wish and get the Hollow Triangle pattern according to their input.
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int rows; cout<<"Enter the number of rows" << endl; cin>>rows; int i,j; i=1; while(i<=rows){ j=1; while(j<=i){ if(j==1 || j==i ||i==rows ) cout<<"*"; else cout<<" "; j++;; } i++; cout <<"\n";//Move to the next line for print } getch(); return 0; }
When the above code is executed, it produces the following results
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int rows; cout<<"Enter the number of rows" << endl; cin>>rows; int i,j; i=1; while(i<=rows){ j=i; while(j<rows){ cout<<" "; j++; } j=1; while(j<=i){ if(j==i || j==1 ||i==rows ) cout<<"*"; else cout<<" "; j++;; } i++; cout<<"\n";//Move to the next line for print } getch(); return 0; }
When the above code is executed, it produces the following results
Program 3
#include <iostream> #include <conio.h> using namespace std; int main() { int rows; cout<<"Enter the number of rows" << endl; cin>>rows; int i,j; i=1; while(i<=rows){ j=1; while(j<=rows){ if(j==i || j==rows ||i==1 ) cout<<"*"; else cout<<" "; j++;; } i++; cout<<"\n";//Move to the next line for print } getch(); return 0; }
When the above code is executed, it produces the following results
Program 4
#include <iostream> #include <conio.h> using namespace std; int main() { int rows; cout<<"Enter the number of rows" << endl; cin>>rows; int i,j; i=1; while(i<=rows){ j=i; while(j<=rows){ if( i==1|| j==i || j==rows) cout<<"*"; else cout<<" "; j++;; } i++; cout<<"\n";//Move to the next line for print } getch(); return 0; }
When the above code is executed, it produces the following results
Suggested for you
Nested while loop in C++ language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…