Program to print hollow star pattern
Write a C++ program to print the hollow right triangle star pattern?
Write a C++ program to print the hollow right triangle star pattern series using while loop in programming. How to print the hollow right triangle star pattern series of n rows using while loop in C++ programming. Logic to print the hollow right triangle star pattern series in C++.
The Program to print hollow star pattern
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include<iostream> using namespace std; int main() { int i,j,n; cout<<"Please enter number of rows: "<<endl; cin>>n; i=1; while(i<=n) { j=1; while(j<i) { cout<<" "; j++; } j=1; while(j<=n) { if(i==1||i==n||j==1||j==n) { cout<<"*"; } else { cout<<" "; } j++; } cout
<<"\n"; i++; } } |
Output
Program to print hollow star pattern
Start with the flowchart of the Program to print a hollow star pattern.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<iostream> using namespace std; int main() { int i, j,rows; cout<<"enter rows:"; cin>>rows; i=1; while(i<=rows) { j=1; while(j<=rows-i) { cout<<" "; j++; } j=1; while(j<=rows) { cout<<"*"; j++; } cout<<endl; i++; } } |
Now, let’s see the Declarations Flow Table.
Variable name | Declaration | initialization | Use(line number) |
i | 5 | 8 | 9|12|24 |
j | 5 | 11|7 | 12|15|18|21 |
rows | 5 | 7 | 9|12|18 |
Output