Write a C++ progam to compute a polynomial

How do I write a C++ program to compute a polynomial using loops?
I'm supposed to solve the polynomial function Pn(X) with x=2 and n=10

Pn(X)=1+x+1/2! x^2+...+1/n! x^n (why is the ... in there?)


i know I plug for x and loop for n (I think)

I'm thinking of going this route with it

1
2
3
4
5
6
7
double polynomial (long int x, long int n)
{double result;
result =(1.0+x+1.0/factorial(2))*x^2;
for (int count=0; count<= n; count++)
result +=double(1.0 /factorial (count)*x^count);
return result;
}

dont I need to declare ?
int x = 2;
and what is the ..... for?
I know I'm missing some small things here I just don't know what!!!
Thank You for reading this
(why is the ... in there?)


Because otherwise, we have to write this:

Pn(X)=1+x+1/2! x^2+1/3! x^3+1/4! x^4+1/5! x^5+1/6! x^6+1/7! x^7+1/8! x^8+1/9! x^9+1/10! x^10

and it's a pain to write that out.
Last edited on
(why is the ... in there?)
I think you should try to understand the math yourself before trying to instruct a computer how to do it.
n is not known so it's impossible to write it all out.

Initialize result to 0 and remove line 3. Those calculations will be done in the loop.

Note that ^ is the bitwise operator. Use the pow function instead.
n is not known so it's impossible to write it all out.


n=10
@peter
if I take out line 3 wont that take out the first part of the equation?
Topic archived. No new replies allowed.