#include <iostream>
using namespace std;
int main()
{
int n;
int k = 0;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (k % 2 == 0)
cout << "+";
else
cout << "-";
k++;
if ((n % 2 == 0) and (j == n - 1))
k--;
}
cout << endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
using namespace std;
int main()
{
int n;
int k = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (k % 2 == 0)
cout << "+";
else
cout << "-";
k++;
if ((n % 2 == 0) and (j == n - 1))
k--;
}
cout << endl;
}
return 0;
}