这是我收到的错误:
c:17:15: error: expected expression before ‘=’ token
suma + = mat[N][M];
这是我的代码:
#include<stdio.h>
#define N 3
#define M 3
int mat[N][M]i,j,k,l,m,n;
int vector[N];
int suma;
int main (void){
for(i=0;i<N;i++){
for(j=0;j<M;j++){
printf("Enter a number: ");
scanf("%d", &mat[N][M]);
}
}
for(k=0;k<N;k++){
suma=0;
for(l=0;l<M;l++){
**suma+ = mat[N][M];
}
vector[i]=suma;
}
return 0;
}
最佳答案
+= != + =
含义:只需写:suma += mat[N][M];
......................................^ 没有空间。
为了完整起见,我将添加 Sourav 提到的内容:
您需要在第一个 for
循环后重置 i
(i=0
),以避免访问越界内存并导致未定义的行为。
关于c - 错误: expected expression before ‘=’ token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34964902/