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
*****
* *
* *
* *
*****
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 ) & & ( row < x ) ) { if( column == 1 ) { cout << "*"; column++; } else if( (column > 1) & & (column < x) ) { cout << " "; column++; } else { cout << "*"; column++; } }e lse { cout << "*"; column++; } } cout << endl; row++; }/ /for pause system("PAUSE") ; return main() ; +3 2 3 }
Post A Comment:
0 comments: