My issue
Runtime error coming while submission for the following search in array problem:
include <stdio.h>
int main(void) {
// your code goes here
int N,X;
int A[N];
scanf(“%d %d”,&N,&X);
for(int i=0;i<N;i++){
scanf(“%d”,A[i]);
}
for(int j=0;j<N;j++){
if(A[j]==X){
printf(“YES”);
}
else{
printf(“NO”);
}
}
}
My code
#include <stdio.h>
int main(void) {
// your code goes here
int N,X,f=0;
int A[N];
scanf("%d %d",&N,&X);
for(int i=0;i<N;i++){
scanf("%d",&A[i]);
}
for(int i=0;i<N;i++){
if(A[i]==X){
f = 1;
}
}
if(f){
printf("YES\n");
}
else{
printf("NO\n");
}
return 0;
}
Learning course: Data structures & Algorithms lab
Problem Link: https://www.codechef.com/learn/course/muj-dsa-c/MUJDSAC06/problems/SEARCHINARR