Advertisement
KristianIvanov00

Untitled

Dec 9th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_GRADE = 1000;
  5. void ReadThePolynom(int Polynom[], int size) //function for Polynom coefficients
  6. {
  7. for (int i = 0; i < size; i++)
  8. {
  9. cin >> Polynom[i];
  10. }
  11. }
  12. void FindTheDerivative(int Polynom[], int size, int Derivative1) //function for Finding Polynom's Devirative
  13. {
  14. cin >> Derivative1;
  15. int coeff = Polynom[0];
  16. int grade = 0;
  17. for (int j = 0; j < size; j++)
  18. {
  19. grade = size - j; // example: size = 4, j = 0, grade of the polynom's value is 0
  20. coeff = Polynom[j]; //coefficient' s first value is the first entered number from the console
  21. for (int i = 1; i <= Derivative1; i++) //finding the 'N' devirative
  22. {
  23. coeff *= grade; // example: devirative of 3x^2 = 9x
  24. grade--;
  25. }
  26. if (coeff != 0) // not to print 0
  27. cout << coeff;
  28. else
  29. {
  30. break;
  31. }
  32. if (grade >= 1) // if the grade is 0, we don't need to print x^0, because x^0 = 1
  33. {
  34. cout << "*X";
  35. if (grade == 1)
  36. {
  37. cout << " + ";
  38. }
  39. }
  40. if (grade > 1) // if the grade is 1, we don't need to print x^1, because x^1 = x
  41. {
  42. cout << '^' << grade << " + ";
  43. }
  44. }
  45. if (Derivative1 > size) // if we have to find a bigger devirative than the biggest coefficient of the polynom, its devirative is 0
  46. {
  47. cout << '0';
  48. }
  49. cout << endl;
  50.  
  51. }
  52.  
  53. int main()
  54. {
  55. int N;
  56. cin >> N;
  57. int Polynom[MAX_GRADE];
  58. ReadThePolynom(Polynom, N);
  59. int Derivative;
  60. cin >> Derivative;
  61. FindTheDerivative(Polynom, N, Derivative);
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement