'How to make a "xoxo" console pattern in C++
How to make like this? I want to try to make it. For example, I have an input whose contents must be odd
input = n > 0;
n = odd numbers;
such as N = 1, then I want the result like this
o
o x o
o
and if n is 3, will be like this
o
o x o
o x x x o
o x o
o
and so on. I want to try to make it, but always fail. This is the code I have:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int x = n;
n += 2;
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
if (i == x-1 || j == x-1) {
cout << "x";
} else {
cout << "o";
}
}
cout << endl;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|