Please I have a little problem with my project. It goes
"A polynomial of degree n is represented as
Pn(x)=A0 + a1x + a2x2 + … + anxn
Where a0, a1, a2, a3 , … , an are constant coefficients. Evaluation of such polynomials may be important if Pn(x) is to be computed many times for different values of x. Design and implement a program that asks for the user the degree of the polynomial n, and values for n+1 coefficient.
Your program should read these values and then in a loop it should prompt the user to enter values for X and compute and print values for the polynomial. Your program should terminate execution if the last two values read for x are equal. Your program should be able to process polynomials of degree 6 or less."
So far i guess that n+1 should be an array, but i don't know what to do. Please I need help

Please let me clear your doubts: a polynomial is a sequence of terms, a term consists of a coefficient and the power of the variable 'x', to store a polynomial, you should define an array which can hold six terms, where does this six come from?
Well,

Your program should be able to process polynomials of degree 6 or less.

Now you've an array in which under each subscript you can store the coefficient of the term you want to store.
What you'll also need is an input routine to get a polynomial into your program, this routine should ask the user for the degree of the polynomial (this is the degree of 'x' in the term which has the highest degree for 'x').
Assuming that you read the degree into a variable called n, you now loop n times (Hint: for / while), every time you ask the user to enter the coefficient for 'x' raised to the power of n and you store it under the appropriate array subscript.
Once you've read the polynomial into the array, you can start an input routine which asks the user to enter a value for 'x'.
From the point you've got the x value for which to evaluate the polynomial, you can compute Pn(x) as follows:

  • Declare a variable to hold the result and initialize it to zero.
  • Iterate over all elements inside the array which holds the coefficients for each term of the polynomial, each time you compute the value of the x-value entered by the user, raised to the power of the value of the loop's counter variable, then you multiply this value by the coefficient of the current term, and finally you add the resulting value to the variable you declared to hold the result.
    This is the computation formula for the value of the nth term in the polynomial: coefficientOfNthTerm * x-value ^ n (note: the [B]^[/B] -sign denotes exponentiation)
    At the end of the loop, the result Pn(x) is stored in the variable which you declared to hold it.

Edited 6 Years Ago by mvmalderen: fix typo

This article has been dead for over six months. Start a new discussion instead.