1. ## question about programming polynomials

our homework is actually a long one, about numerical analysis, roots of poylnomials, etc. the problem is i don't know how to do the first step, which is storing/saving a user-input polynomial(eg this form: x^3-4x^2+2). do i use arrays?strings? and how do you save the polynomial as a function so that you can get the value of the polynomial when a value for x is given(say x = 2, then, from the ex above, f(x) = -6). 2. I don't know what option is best for your case, but why don't you experiment with different approaches? 3. say i use strings to store the polynomial, how can i save it as a function? 4. You can't save it directly as a function but rather pass it to a function that will translate it to the proper operations. 5. how? 6. I have an idea about how to store the polynomial. My opinion is, store it in a struct that has two elements: an integer "maxPow" that represents the bigger power and an array of size "maxPow" that will store the coefficients of each part of the polynomial. 7. Originally Posted by firehydrant how?
For that you'll need to know how to parse math expressions. There are many tutorials online, compiler expression parsing such get you started!  8. we haven't tackled structs yet in class, so as of the moment, i can't use those.

if i use strings to store the polynomial, is there a way to pick out the numeric parts of it? that way, i can assign it as coefficients or exponents in my function. 9. Originally Posted by firehydrant if i use strings to store the polynomial, is there a way to pick out the numeric parts of it? that way, i can assign it as coefficients or exponents in my function.
Of course there is, but as i said, that can be done by parsing the math expressions inside it.
And since you don't know structs yet, this "translation" has to be done everytime you want to call that polynomial. 10. how do i do it exactly? 11. Originally Posted by firehydrant how do i do it exactly?
Search for Math Expression Parsing 12. ok
Thanks! 13. The simplest way is ask user from number of degree(n).
and ask coefficient of each term.

Code:
```Deg of polynomial: 2
coefficient of x^2 : 1
coefficient of x^1 : -4
coeficient of x^0 : 2``` 14. i have a suggestion. but i think it will make the program a bit lengthy.
anyway let me.

i think u ppl hav heard about infix and postfix expressions.
first of all, consider the input polynomial as an INFIX expression.
convert it to POSTFIX and then evaluate it by giving values to variables. 15. how do you that math expression parsing? Popular pages Recent additions array, easy, polynomials, program, strings 