CPP Program to generate hollow star squre

This C++ program generate hollow star square using for loop. The program basically manipulate the space before the star(*)  and after the stars. The program was generated on Windows 10 and compiled and executed on Dev C++ IDE.

/*		program to print blank rhombus
		made by		: rakesh kumar
*/

#include
#include
using namespace std;
int main()
{
	int n,i,j,k,star;
	cout<<"\n Enter any integer no :"; cin>>n;
	for(i=1;i<=n;i++)
	{
		for(k=1;k<=n-i;k++)
			cout<<" ";
		star=1;
		for(j=1;j<=2*i-1;j++)
		   {
		   	 
			 if(star==1|| star==2*i-1)
			  	cout<<"*";
			 else
			 	cout<<" " ;
			  star++; 	
			}
		cout<<"\n"; } // reverse pattern for(i=n-1;i>=1;i--)
	{
		for(k=1;k<=n-i;k++)
			cout<<" ";
		star=1;
		for(j=1;j<=2*i-1;j++)
		   {
		   	 
			 if(star==1|| star==2*i-1)
			  	cout<<"*";
			 else
			 	cout<<" " ;
			  star++; 	
			}
		cout<<"\n";
	}
	
 	return 0;	
}

Here is the sample output of hollow star square program

hollow star square
C++ program output of hollow star square using for loop

Related Posts

If you like CBSEToaday and would like to contribute, you can also write an article using submit article or mail your article to contribute@cbsetoday.com See your article appearing on the cbsetoday.com main page and help other students/teachers.