Construct an algorithm that has input an integer n ≥ 1, numbers x0, x1,...,xn, and a number x and that produces as output the product (x-xo)(x-x1)(x - xn).

How would you do this step-by-step on paper with a specific set of inputs?

As this seems like a homework task, here is a nudge in the right direction -

Create and Initialize your variable 'MyVariable' to 1.
Loop through your list of numbers x0, x1, ..., xn and so on.
For each number xi in your list, subtract it from x and update the 'MyVariable' by multiplying it with the result.
After the loop ends, the 'MyVariable' will contain the expected result.
Return the 'MyVariable' as your output.

Well, here is the basic algorithm for what you are looking for.

Algorithm CalculatePolynomialProduct(n, x0, x1, ..., xn, x):
    product = 1
    for i = 0 to n:
        product = product * (x - xi)
    end for
    return product
End Algorithm

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.