I've made the code above and I've used 2 different compilers, one says "Segmentation Fault" and the other one says "handle_exceptions: Exception: STATUS_STACK_OVERFLOW". Here is the code.
int main() {
int k, x, f, i, j, tmp, ct;
scanf("%d %d", &k, &x);
int w[k];
for( f = 0; f<k; f++){
scanf(" %d", &w[f]);
}
while(x--){
scanf("%d %d", &i, &j);
tmp = 3;
for(ct = j; i<=ct<=j; ct--){
if(tmp > w[ct]){
tmp = w[ct];
}
}
printf("%d\n", tmp);
}
return 0;
}
I've commented this code, line by line, and testing and I've the error here:
int w[k];
I don't know what I can do, because the k variable is already defined when the declaration of this vector happens. Can somebody help me?