Something like this could work. You need basic understanding of nested loops to be able to do this question.
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char const *argv[]) {
int rows, cols, i, j;
printf("Enter rows for box: ");
if (scanf("%d", &rows) != 1) {
printf("Invalid rows
");
exit(EXIT_FAILURE);
}
printf("Enter columns for box: ");
if (scanf("%d", &cols) != 1) {
printf("Invalid columns
");
exit(EXIT_FAILURE);
}
printf("
2D Array Box:
");
for (i = 1; i <= rows; i++) {
for (j = 1; j <= cols; j++) {
printf(" --- ");
}
printf("
");
for (j = 1; j <= cols; j++) {
printf("| |");
}
printf("
");
}
/* bottom "---" row */
for (i = 1; i <= cols; i++) {
printf(" --- ");
}
return 0;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…