# Thread: How to solve a polynomial given "x" in C.

1. ## 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:

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.

Thanks

2. double answer = 3 * (x * x) - 5 * (x * x) + 6;

How many x are there bold above?
How many should there be?

Tim S.

3. Originally Posted by stahta01
double answer = 3 * (x * x) - 5 * (x * x) + 6;

How many x are there bold above?
How many should there be?

Tim S.
I see what you mean, but when I run it, it does run, I get this error in codeblocks:
Process terminated with status -1073741510 (0 minutes, 5 seconds)

4. %d means integer
%f means float/double in printf

`H:\SourceCode\Projects\TestProjects\testc\main.c|8|warning: format '%d' expects argument of type 'int', but argument 2 has type 'double' [-Wformat]|`