Some numbers like 1,2,3,4,.... are provided from the command line. Considering them to be roots of a polynomial of that degree< equal to number of roots > , i was trying to find the coefficients of the constructed polynomial, i was using the concept of multiplication of two single degree polynomials.
for e.g if the numbers are 1,2 and3.
the P(x) == (x-1)(x-2)(x-3).
so if give 1 and 2 in the command line. the sample output should be 1 , -3, 2.
Please help me......

8 Years
Discussion Span
Last Post by jits_aps90


If two roots are provided a,b

then the equation will be :

x^2 - (a + b)x + (ab) = 0

If three roots are provided a,b,c

then the equation will be (not sure) :

x^3 - (a+b+c)x^2 + (ab+bc+ca)x - (abc) = 0


1) First, represent a polynomial (of the form c_0 + c_1*x + c_2*x^2 + .... c_n*x^n) is represented by an array with elements (c_0, c_1, c_2, c_3, .... c_n).

2) Work out how to multiply two arbitrary polynomials together. ie. given a polynomial A (a_0, a_1, a_2, a_3, .... a_n) and a polynomial B (b_0, b_1, b_2, b_3, .... b_m) work out how to obtain a polynomial A*B = C = (c_0, c_1, c_2, c_3, .... c_(m+n)). Hint: The process to produce C from A and B is called convolution.

3) For the first root on the command line, create a polynomial X = (root, 1).

4) For all other roots on the command line;
a) create a polynomial Y = (root, 1)
b) obtain a polynomial Z = X*Y using the approach worked out in Step 2.
c) set X = Z

5) Voila!!!

Make it count rep added.

ya thnks dear...
actually, thats a solution when you have known number of roots...
But i am taking some number random number of roots from command line....
thats why i am facing a problem in coding it....
bye tc


hi thanks a lot!
in fact i had just worked out the same problem with the same logic.
u r too good!
bye tc

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.