I am trying to add some polynomials after multiplying each by a different constant. I have been able to setup the arrays and multiply by the constants, but when I get to the addition of each position in the different arrays(polynomials) into a new array but I get the error "Variable-sized object may not be initialized" and the program does not compile. Also the multiplication always yields 0 no matter what the values of the arrays or the values of the c's are. I am not sure what exactly is wrong.
Any help would be appreciated
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
FILE *fp;
fp = fopen("approximating the wronskian w/o wronskian.txt", "w");
fprintf(fp, "| c1 | c2 | c3 | value |\n");
long int f1[3]= {1, 3, 4};
long int f2[3]= {3, 4, 5};
long int f3[3]= {3, 6, 8};
for(int c1 = 0; c1 < 100; c1++)
{
for(int c2 = 0; c2 < 100; c2++)
{
for(int c3 = 0; c3 < 100; c3++)
{
for(int i = 0; i < 3; i++)
{
f1[i] *= c1;
f2[i] *= c2;
f3[i] *= c3;
int w[i] = f1[i] + f2[i] + f3[i];
fprintf(fp, "| %d | %d | %d | %ld | %ld | %ld |\n", c1, c2, c3, f1[i], f2[i], f3[i]);
}
}
}
}
fclose(fp);
return 0;
}
int w[i] = f1[i] + f2[i] + f3[i];. What is that trying to do? Did you mean it to be instead:int w = f1[i] + f2[i] + f3[i];wat the top of the function as:long w[3];and then within the loop:w[i] = f1[i] + f2[i] + f3[i];