Вывод квадрата из точек диагонали и средние линии которого - звёздочки

using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if ((i == j) || (i + j == n + 1) || (i == n) || (j == n))
        cout << "* ";
      else
        cout << ". ";
      if(i == n/2){
        cout << "* ";
      }
     
    }
  }

return 0;
} ```

Ответы (1 шт):

Автор решения: Harry

Это нужно?

#include <iostream>

using namespace std;

void square(int n)
{
    for(int row = 0; row < n; ++row)
    {
    for(int col = 0; col < n; ++col)
        cout << (row == col || row + col == n - 1 ||
                 abs(2*row - n + 1) < 2 || abs(2*col - n + 1) < 2 ? '*' : '.');
        cout << "\n";
    }
}


int main()
{
    int n;
    cin >> n;
    square(n);
}
→ Ссылка