C++ Online Compiler
Example: C++ Program to print Hollow Square with Diagonal
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to print Hollow Square with Diagonal #include <bits/stdc++.h> using namespace std; int main() { int x = 0, y = 0; unsigned int sS = 0; cout << "-----Enter the side of a square-----\n"; cin >> sS; cout << endl; for (x = 1; x <= sS; ++x) { for (y = 1; y <= sS; ++y) { // It will check boundary conditions // It will check diagonal and secondary diagonal conditions if ((x == 1) || (x == sS) || (y == 1) || (y == sS) || (x == y) || (y == (sS - x + 1))) cout << "*"; else cout << " "; } // It will print the new line cout << endl; } return 0; }
12
Output
Clear
ADVERTISEMENTS