Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int MAX_GRADE = 1000;
- void ReadThePolynom(int Polynom[], int size) //function for Polynom coefficients
- {
- for (int i = 0; i < size; i++)
- {
- cin >> Polynom[i];
- }
- }
- void FindTheDerivative(int Polynom[], int size, int Derivative1) //function for Finding Polynom's Devirative
- {
- cin >> Derivative1;
- int coeff = Polynom[0];
- int grade = 0;
- for (int j = 0; j < size; j++)
- {
- grade = size - j; // example: size = 4, j = 0, grade of the polynom's value is 0
- coeff = Polynom[j]; //coefficient' s first value is the first entered number from the console
- for (int i = 1; i <= Derivative1; i++) //finding the 'N' devirative
- {
- coeff *= grade; // example: devirative of 3x^2 = 9x
- grade--;
- }
- if (coeff != 0) // not to print 0
- cout << coeff;
- else
- {
- break;
- }
- if (grade >= 1) // if the grade is 0, we don't need to print x^0, because x^0 = 1
- {
- cout << "*X";
- if (grade == 1)
- {
- cout << " + ";
- }
- }
- if (grade > 1) // if the grade is 1, we don't need to print x^1, because x^1 = x
- {
- cout << '^' << grade << " + ";
- }
- }
- if (Derivative1 > size) // if we have to find a bigger devirative than the biggest coefficient of the polynom, its devirative is 0
- {
- cout << '0';
- }
- cout << endl;
- }
- int main()
- {
- int N;
- cin >> N;
- int Polynom[MAX_GRADE];
- ReadThePolynom(Polynom, N);
- int Derivative;
- cin >> Derivative;
- FindTheDerivative(Polynom, N, Derivative);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement