variable-sized object may not be initialized
#include<stdio.h>
int main(void){
int N;
scanf("%d",&N);
int a[N] = {0};//错误在这,可以用变量定义数组,但不能初始化
for(int i=0;i < N;++i){
scanf("%d",&a[i]);
}
int M,sum = 0;
scanf("%d",&M);
while(N--){
if(a[N] == M)
++sum;
}
printf("%d",sum);
}
- 可以用变量定义数组,但不能初始化
正确写法
#include<stdio.h>
int main(void){
int N = 0;
scanf("%d",&N);
int a[N];
for(int i=0;i < N;++i){
scanf("%d",&a[i]);
}
int M,sum = 0;
scanf("%d",&M);
while(N--){
if(a[N] == M)
++sum;
}
printf("%d",sum);
}