#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);
}
标签:int,sum,object,sized,++,printf,variable,initialized,scanf
From: https://www.cnblogs.com/bing0426/p/17459024.html