408,572 views
25 votes
25 votes
Write a program that reads in the size of the side of a square and 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

User Prateek Prasad
by
2.8k points

1 Answer

12 votes
12 votes

Answer:

Step-by-step explanation:

#include <iostream>

using std::cout;

using std::endl;

using std::cin;

int main()

{

int side, rowPosition, size;

cout << "Enter the square side: ";

cin >> side;

size = side;

while ( side > 0 ) {

rowPosition = size;

while ( rowPosition > 0 )

if ( size == side

cout << '\\';

--side;

}

cout << endl;

return 0;

}

User Afton
by
3.4k points