The question I am working on asks me to write code that prints each value from -1
to 1
inclusive, incremented by a value of 0.01
to solve the mathematical function f(x) = x^2 + 4
(to 4 decimal places).
example:
f(-1.00) = 5.0000
f(-0.99) = 4.9801
...
f(1.00) = 5.0000
Problem:
I do not get the last line of the code: f(1.00) = 5.0000
. My question is how do I modify my program so that it does appear, and can you also explain why it does not appear in the first place, please?
Code:
Below is my code. It is printing out every value of y
when x
is between 0
and 1
, except for f(1.00) = 5.0000
...
double numberForQ4 = -1.00;
double valueOfY = 0;
for ( numberForQ4 = -1.00; numberForQ4 <= 1.00; numberForQ4 += 0.01 ) {
valueOfY = numberForQ4 * numberForQ4 + 4;
printf( "f(%.2f) = %.4f \n", numberForQ4, valueOfY );
}