I want to print this if the user typed in for example 2:
+---+
|\\ /|
| X |
|/ \\|
+---+
It\'s a square with a size of 2n+1 for each side of i
Here is a slightly modified version of your program that prints spaces where you don't specify anything else.
You can use it as a starting point.
#include
int main(void)
{
int size = 2;
int i, j;
char ch;
for (int i = 0;i < ((size * 2) + 1);i++){
for (int j = 0; j < ((size * 2) + 1);j++){
ch = ' ';
if (i == 0 && (j == 0 || j == size * 2)){
ch = '+';
}
else if (i == 0 && j != i){
ch = '-';
}
if (i > 0 && (j == 0 || j == size * 2)){
ch = '|';
}
printf("%c", ch);
}
printf("\n");
}
return 0;
}
This prints
+---+
| |
| |
| |
| |