c中的二维数组 我得到了一个小错误,搞砸了我.. 你可以发现任何错误,而我应该看到
1 2 3 4 5 6 7 8 9
但我的操作是
1 2 4 4 5 7 7 8 9
#include <stdio.h>
int main(int argc,char* argv[])
{
int m;
scanf("%d",&m);
int a[m][m],i,j;
for(i=0;i<=m;i++){
for(j=0;j<=m;j++){
scanf("%d",&(a[i][j]));
printf("%d",a[i][j]);
}
}
for(i=0;i<=m;i++){
for(j=0;j<=m;j++){
printf("%d",a[i][j]);
printf("\t");
}
printf("\n");
}
}
答案 0 :(得分:2)
宣言:
Uncaught TypeError: Cannot read property 'isSynchronized' of undefined
at constructor.addCls (ext-all-rtl-debug.js?_dc=1487248312797:34688)
at constructor.addCls (ext-all-rtl-debug.js?_dc=1487248312797:63226)
at constructor.disable (ext-all-rtl-debug.js?_dc=1487248312797:63902)
at constructor.callParent (ext-all-rtl-debug.js?_dc=1487248312797:11709)
at constructor.disable (ext-all-rtl-debug.js?_dc=1487248312797:123642)
at constructor.ddDisable (ext-all-rtl-debug.js?_dc=1487248312797:175799)
at constructor.handleMouseDown (ext-all-rtl-debug.js?_dc=1487248312797:134260)
at constructor.handleMouseDown (ext-all-rtl-debug.js?_dc=1487248312797:138266)
at constructor.callParent (ext-all-rtl-debug.js?_dc=1487248312797:11709)
at constructor.handleMouseDown (ext-all-rtl-debug.js?_dc=1487248312797:139491)
表示您的数组包含int a[m][m];
行和m
列, 编号从m
到0
。由于您的m-1
条件,您正在尝试访问不属于您的阵列的元素。
从以下位置更改两个循环:
<=m
你现在拥有的:
for(i=0;i<=m;i++){
for(j=0;j<=m;j++){
scanf("%d",&(a[i][j]));
printf("%d",a[i][j]);
}
}
您可以阅读有关索引和数组here的更多信息。
答案 1 :(得分:1)
你的循环超出了数组的末尾。像int a[m]
这样的数组的元素从0到m-1,所以你的循环应该是这样的:
for(i=0;i<m;i++){
for(j=0;j<m;j++){