ChameL1oN

4

Nov 26th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<math.h>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. void r(double x,double x2)
  8. {
  9. double s, n, eps;
  10. int i;
  11. eps = 0.00001; // точность
  12. double e = 0.1; // шаг
  13.  
  14.  
  15.  
  16. for (double j = x; j < x2; j += e)
  17. {
  18. n = 1;
  19. s = 0;
  20. i = 1;
  21. while (abs(n) > eps)
  22. {
  23. s += n;
  24. n *= -1.0 * j * j / ((2 * i - 1) * (2 * i));
  25. i++;
  26. }
  27. if (j > -0.01 && j < 0.01)cout << "x = " << 0 << " Сумма: " << s << " cos(x): " << cos(j) << endl;
  28. else
  29. cout << "x = " << left << setw(10) << j << "Сумма: " << setw(15) << s << "cos(x): " << setw(10) << cos(j) << endl;
  30.  
  31. }
  32.  
  33. }
  34.  
  35. void main()
  36. {
  37. setlocale(LC_ALL, "rus");
  38. double x,x2;
  39. cout << "Введите число х\n";
  40. cin >> x;
  41. cout << "Введите число х2\n";
  42. cin >> x2;
  43. r(x,x2);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment