I have a problem in writing a code that accept a polynomia function from the user.The program shouldn't accept the cofficient and exponent at ones not separately.For example 5x^50+x^8+x is a single entery from the user.
polynomial function
Collapse
X
-
I'm not getting the last part. If you could please explain againOriginally posted by selamI have a problem in writing a code that accept a polynomia function from the user.The program shouldn't accept the cofficient and exponent at ones not separately.For example 5x^50+x^8+x is a single entery from the user. -
It seems to me that you would need to write a function that takes a character string as input and parses it to a polynomial structure of some kind. (An class consisting of an array of coefficients plus some operations, for instance.)
If you can assume that your user writes the polynomial in order from the highest degree term to the lowest degree term, that would help in the parsing. You might then consider first eliminating all whitespace (spaces and tabs) from the input, so that you can assume that the only characters that separate monomial terms are + or -.
The ^ character will indicate the term of each monomial term. (If there is no ^ term, then it's either degree 1 or 0. If there's no x, then it's degree zero.)
I suppose that if you process the string twice, you won't need to assume any kind of ordering. (Process once to determine the maximum degree and thereby the necessary memory allocation for the coefficients, and process a second time to fill in the coefficients.)
I hope that helps a little. -- PaulComment
Comment