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 square of all side sized between 1 and 20. for example, if your program reads a size of 5, it should print.
#include <iostream>
usingnamespace std;
int main()
{
int x, square, c;
c = 1;
cout << "Enter side of a square: ";
cin >> x;
square = x * x;
while ( c <= square ) {
cout << "*";
if ( c % x == 0 )
cout << "\n";
c++;
}
cout << endl;
return 0;
}
/* Recode by Dipen45 since to use with while */
#include <iostream>
usingnamespace std;
int main()
{
int i, j, num;
i = 1;
j = 1;
cout << "Enter a side of square: ";
cin >> num;
while ( i <= num ) {
j = 1;
while ( j <= num ) {
if ( i == 1 || i == num || j == 1 || j == num )
cout << "*"; // if any one out of 4 argument is true then it will print * otherwise ' '
else
cout << " "; // prints if i=2 and j = 2
j++;
}
cout << endl;
i++;
}
return 0;
}