I have written a program to calculate y values according to given x values for the function y = (sqrt(3+x^2))/(20x^2+sqrt(x)). Using two counters, one for x values [i], and one for y values [n]. My x values show up fine, however, the y values return zeroes. What would be the mistake here? Very appreciated.
for (i = 0; i < 30; i++)
{
x[i] = 20 i * 2 + 3;
}
for (n = 0; i < 30 && n < 50; i++, n++)
{
y[n] = (sqrt(3 + (pow(x[i], 2))))) / (20 * pow(x[i], 2) + sqrt(x[i]));
}
for (i = 0, n = 0; i < 30 && n < 50; i++, n++)
printf("x %lf, y %lf", x[i], y[n]);
return 0;
}
You are continuing to use
i, without re-initializing it to0after the firstforloop. Because the value ofistays at the value oftimes, the secondforloop never gets to run. But you rightly initialized it while printing the values ofx,yin the final loop.Change your second
forloop to