Your problem is in this line:
int a,query,in,n,b[n],sum[a];
What is the meaning of b[n]
? And of sum[a]
? Assuming that you would like to have a language with magically growing arrays, C is a bad choice.
In C language arrays are a structure with size known at compile time. Anyway, let's assume that your compiler supports the horrible hack of variable-length arrays. You can do this:
#include
#include
#include
int main(void) {
int a, query, in , n;
scanf("%d", &query);
int sum[query+1];
for (a = 1; a <= query; a++) {
sum[a] = 0;
scanf("%d", &in);
int b[in+1];
for (n = 1; n <= in ; n++) {
b[n] = 1 + 7 * (n - 1) + 6 * (n - 1) * (n - 2) + (n - 1) * (n - 2) * (n - 3);
sum[a] = sum[a] + b[n];
}
}
for (a = 1; a <= query; a++) {
printf("%d\n", sum[a]);
}
return 0;
}
Note the changes: first you need to know the size of the array, then you can allocate it. Moreover, I increased the size of the array in order to support your choice of starting from 1. Lastly I also zeroed the initial value for sum
array.