You need to draw the left side of the box, then add space characters to separate the left from the right side, then draw the right side of the box.
You can do this by writing an outer loop that spans the height of the box and an inner loop that spans the width of the box. The latter adds space characters.
#include <stdio.h>
int main() {
int dimension_x, dimension_y;
printf("Give first size (x): ");
scanf("%d", &dimension_x);
printf("Give second size (y): ");
scanf("%d", &dimension_y);
// Draw the top of the box.
printf("%c", 201);
for (int x = 0; x < dimension_x; x++)
{
printf("%c", 205);
}
printf("%c
", 187);
// Draw the sides of the box.
for (int y = 0; y < dimension_y; y++)
{
// Left side of box.
printf("%c", 186);
// Space separating the left and right sides.
for (int x = 0; x < dimension_x; x++)
{
printf(" ");
}
// Right side of box.
printf("%c
", 186);
}
// Draw the bottom of the box.
printf("%c", 200);
for (int x = 0; x < dimension_x; x++)
{
printf("%c", 205);
}
printf("%c", 188);
return 0;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…