With a binary read from the file writes garbage in 1 factor, the rest is all fine. Text reading do not know how to organize, here's the code: http://www.cyberforum.ru/c-beginners/thread1865879.html#post9841925
Closed due to the fact that off-topic participants are Vladimir Martyanov , Vlad from Moscow , post_zeew , aleksandr barakin , Harry Dec 2 '16 at 7:48 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Vladimir Martyanov, post_zeew, aleksandr barakin, Harry
1 answer
Nothing "great" is there.
If the degree of a polynomial is n , then the number of coefficients of such a polynomial is n+1 . You are well aware of this, because in the Enter function you enter exactly n+1 coefficients.
However, you allocate memory everywhere only under the n elements of the array and write-read only for n elements. Therefore, in Enter there is a departure beyond the limits of the array and one coefficient is then lost. Throughout the program, such errors are scattered, including in the functions of reading and writing.
You must first decide what n is — the degree of the polynomial or the size of the coefficient array. If n is the degree of a polynomial, then increase the size of the array to n+1 and mention it everywhere. If n is the size of the coefficient array, then it must be remembered that the degree of the polynomial is n-1 .
Either that or that way.
i=nyou need to writei=n-1. - KoVadimnis — the degree of the polynomial or the size of the coefficient array. A polynomial of degreenhas ann+1coefficient. Ifnis the degree of a polynomial, then vice versa, it is necessary to increase the size of the array ton+1and mention it everywhere. - AnT