How to solve a polynomial given "x" in C.
I am 17 and trying to learn C, so I bought "Programming in C" by Stephan Kochan. I have made it to the 4th chapter on the 6th exercise and I cannot get this simple question:
Quote:
Write a program to evaluate the polynomial shown here:
3x^3 - 5x^2 + 6
for x = 2.55
I did this:
Code:
//Polynomial Solver
#include <stdio.h>
int main(void)
{
double x = 2.55;
double answer = 3 * (x * x) - 5 * (x * x) + 6;
printf ("3x^3 - 5x^2 + 6 = %d\n", answer);
return 0;
}
but it will not give me the correct answer.
I know this is really basic, but please help!
Thanks