Print Friendly and PDF
Square of Asterisks) Write a program that reads in the size of the side of a square then prints a hollow square of that size out of asterisks and blanks. Your program should work for squares of all side sizes between 1 and 20.
Square of Asterisks) Write a program that reads in the size of the side of a square then prints a hollow square of that size out of asterisks and blanks. Your program should work for squares of all side sizes between 1 and 20. 

For example, if your program reads a size of 5, it should print
*****
* *
* *
* *
*****

Solution:

#include
#include
#include
using namespace std;
int main()
{
int x;
int row = 1;
int column;
cout << "Enter the X (more than 1) : ";
cin >> x;
while( row <= x )
{
column = 1;
while( column <= x )

{
if( row == 1 )
{
cout << "*";
column++;
}
else if(( row > 1 ) &amp; &amp; ( row < x ) )
{
if( column == 1 )
{
cout << "*";
column++;
}
else if( (column > 1) &amp; &amp; (column < x) )
{
cout << " ";
column++;
}
else
{
cout << "*";
column++;
}
}e
lse
{
cout << "*";
column++;
}
}
cout << endl;
row++;
}/
/for pause
system("PAUSE") ;
return main() ;
+3
2
3

}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: