fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int numRows = 4;
  6. int numCols = 6;
  7.  
  8. for (int i = 1; i <= numRows; ++i) {
  9. for (int j = 1; j <= numCols; ++j) {
  10. // Print asterisks for the first and last rows
  11. // Print asterisks only at the beginning and end of other rows
  12. if (i == 1 || i == numRows || j == 1 || j == numCols) {
  13. cout << "* ";
  14. } else {
  15. cout << " "; // Print spaces for other positions
  16. }
  17. }
  18. cout << endl;
  19. }
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
* * * * * * 
*         * 
*         * 
* * * * * *