fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. int rows, cols;
  8.  
  9. cin >> rows;
  10. cin >> cols;
  11.  
  12. cout << "Rectangle of dimensions " << rows << "*" << cols << endl;
  13.  
  14. // Main logic to print hollow rectangle.
  15. for (int i = 0; i < rows; i++) {
  16. for (int j = 0; j < cols; j++) {
  17.  
  18. // If the index is at the border, then print *.
  19. if (i == 0 || i == rows - 1 || j == 0 || j == cols - 1)
  20. cout << "* ";
  21. else
  22. cout << " ";
  23. }
  24. cout << endl;
  25. }
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 5276KB
stdin
4 6
stdout
Rectangle of dimensions 4*6
* * * * * * 
*         * 
*         * 
* * * * * *