Answer the question
In order to leave comments, you need to log in
How to make a function that converts the degree and coefficients of a polynomial into a finished equation?
There are, for example, such fields in the class as:
int degree; //степень многочлена
double *koef; //на массив коэффициентов многочлена
Answer the question
In order to leave comments, you need to log in
#include <iostream>
void printPolynom(double* coefs, int degree, std::ostream& os)
{
static const char VAR = 'x';
bool first = true;
for (int i = degree; i >= 0; --i) {
double coef = *coefs;
coefs++;
if (!first && coef > 0.0) {
os << "+";
}
first = false;
os << coef;
for (int j = 0; j < i; ++j)
os << '*' << VAR;
}
}
int main()
{
const int degree = 3;
double coefs[degree + 1] = { 9, 3, 12, -1 };
printPolynom(coefs, degree, std::cout);
std::cout << "\nDone";
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question