c++程序请问这哪里错了?出错在哪里?

2025-02-25 14:02:22
推荐回答(6个)
回答1:

问题就是不能这样定义数组 可以这样改
#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 a[i]=(int *)malloc(sizeof(int)*m);
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;
}
}

回答2:

静态数组的维数不能是变量,所以只能用动态数组,你可以用二级指针实现。
int **a,i,j,s;
...
// 输入m和n
..
// 开辟动态数组
a = new int*[n];
for (i = 0; i < n; i++)
{
a[i] = new int[m];
}

其他的就跟你的程序一样。

回答3:

int a[n][m]

首先 m, n 没有定义
其次 m, n 是变量, 变量不能用来定义数组的, 必须用常量 比如 int a[10][12];

回答4:

m,n未定义
C++不支持动态数组,即定义一个数组之前必须知道数组的大小

回答5:

int a[n][m]数组的定义不能使用变量

回答6:

m,n没定义,其次数组【】里不能使变量