Your variables are uninitialized. As a result your program invokes Undefined Behavior.
For example you do not initialize n
, but you then declare int b[n]
. What is the size of array b
? Nobody really knows, since n
has a garbage value.
Start by figuring out what the values of your variables should be, and then start coding.
Array indexing starts from 0, thus your for loops are not looking good.
Change this:
for(a=1;a<=query;a++)
to this:
for (a = 0; a < query; a++)