wel*_*rld 11 multidimensional-array
如何使用scanf为用户输入打印一个二维数组,名为grid [] []的数组和一个for循环?
如果用户输入3 5,输出将是:
.....
.....
.....
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止编写的代码(这里是新手):
#include <stdio.h>
#define MAX 10
int main()
{
int grid[MAX][MAX];
int row, col;
int i,j;
printf("Please enter your grid size: ");
scanf("%d %d", &row, &col);
for (i=0; i<MAX; i++)
for //i gave up here
}
Run Code Online (Sandbox Code Playgroud)
这只是我任务的整个阶段的一小部分:
Enter number of rows and columns followed by list of words (hit enter twice to end list): 10 15
quick
brown
fox
jumped
over
lazy
dog
00 . . . . . . . . . . . . . . .
01 . . . . . . . . . . . . . . .
02 . . . . . . . . . . . . . . .
03 . . . . . . . . . . . . . . .
04 . . . . . . . . . . . . . . .
05 . . . . . . . . . . . . . . .
06 . . . . . . . . . . . . . . .
07 . . . . . . . . . . . . . . .
08 . . . . . . . . . . . . . . .
09 . . . . . . . . . . . . . . .
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0. quick
1. brown
2. fox
3. jumped
4. over
5. lazy
6. dog
Run Code Online (Sandbox Code Playgroud)
允许的函数,应该包含在代码中:字符串函数 - strlen(),strcpy(),strcat(),strchr(),strcmp(),strstr()
必须使用2d数组
必须使用fgets来表达文字.输出必须符合确切的格式.
Nom*_*meN 12
这有什么帮助吗?
#include <stdio.h>
#define MAX 10
int main()
{
char grid[MAX][MAX];
int i,j,row,col;
printf("Please enter your grid size: ");
scanf("%d %d", &row, &col);
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
grid[i][j] = '.';
printf("%c ", grid[i][j]);
}
printf("\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)