fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. int main() {
  5. const int n = 9;
  6. bool isUpDownBox = false,
  7. isLeftRigthBox = false,
  8. isDiagonal = false;
  9.  
  10. for (int i = 0; i < n; ++i) {
  11. for (int j = 0; j < n; ++j) {
  12. isUpDownBox = i == 0 || i == n - 1;
  13. isDiagonal = !isUpDownBox && (i == j);
  14. isLeftRigthBox = !isUpDownBox && (j == 0 || j == n - 1);
  15.  
  16. if (isUpDownBox) {
  17. std::cout << '*';
  18. } else if (!isLeftRigthBox) {
  19. if (isDiagonal) {
  20. std::cout << '*';
  21. } else {
  22. std::cout << ' ';
  23. }
  24. } else {
  25. std::cout << '*';
  26. }
  27. }
  28. std::cout << std::endl;
  29. }
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
*********
**      *
* *     *
*  *    *
*   *   *
*    *  *
*     * *
*      **
*********