DSA - Loop
1. Print x:
int main() {
int n;
cin >> n;
for (int i = 0; i < n * n; i++) {
int row = i / n;
int col = i % n;
if (row == col || row + col == n - 1) {
cout << "*";
} else {
cout << " ";
}
if (col == n - 1) {
cout << endl;
}
}
}
1. Print x:
int main() {
int n;
cin >> n;
for (int i = 0; i < n * n; i++) {
int row = i / n;
int col = i % n;
if (row == col || row + col == n - 1) {
cout << "*";
} else {
cout << " ";
}
if (col == n - 1) {
cout << endl;
}
}
}
Комментарии
Отправить комментарий