问题就是不能这样定义数组 可以这样改
#include
#include
main()
{
int n,m,i,j,s;
s=0;
printf("enter a value for the n\n");
scanf("%d",&n);
printf("enter a value for the m\n");
scanf("%d",&m);
int **a=(int **)malloc(sizeof(int *)*n);
for(i=0;i
for(i=0;i
for(j=0;j
printf("input value\n");
scanf("%d",&a[i][j]);
s=s+a[i][j];
}
printf("%d lines and is:",i);
printf("%d\n",s);
s=0;
}
for(j=0;j
for(i=0;i
s=s+a[i][j];
}
printf("the %d coumn and is:");
printf("%d\n",s);
s=0;
}
}
静态数组的维数不能是变量,所以只能用动态数组,你可以用二级指针实现。
int **a,i,j,s;
...
// 输入m和n
..
// 开辟动态数组
a = new int*[n];
for (i = 0; i < n; i++)
{
a[i] = new int[m];
}
其他的就跟你的程序一样。
int a[n][m]
首先 m, n 没有定义
其次 m, n 是变量, 变量不能用来定义数组的, 必须用常量 比如 int a[10][12];
m,n未定义
C++不支持动态数组,即定义一个数组之前必须知道数组的大小
int a[n][m]数组的定义不能使用变量
m,n没定义,其次数组【】里不能使变量