Here, we display an Hollow triangle Patternprogram 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.
Floyd’striangle star pattern 1
Program 1
#include
#include
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
Floyd’s triangle star pattern 1
Floyd’striangle star pattern 2
Program 2
#include
#include
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
When the above code is executed, it produces the following results
Floyd’s triangle star pattern 2
Floyd’striangle star pattern 3
Program 3
#include
#include
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
Floyd’s triangle star pattern 3
Floyd’striangle star pattern 4
Program 4
#include
#include
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