Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <math.h>
  4. #include <iomanip>
  5. #include <conio.h>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. typedef double (*func)(double);
  11. double y_from_x (double);
  12. double s_from_x(double);
  13. void Out_Rez(double, double, double, func);
  14. double n;
  15.  
  16. double s_from_x(double a) {
  17. double sx = 1;
  18. double shag = 1;
  19. for (double k = 1; k <= n; k++)
  20. {
  21. shag *= -1 * a * a / 2.0 / k / (2 * k - 1);
  22. sx += shag * (2 * k * k + 1);
  23. }
  24. return sx;
  25. }
  26.  
  27. double y_from_x (double a) {
  28. return (1 - a * a / 2.) * cos(a) - a / 2. * sin(a);
  29. }
  30.  
  31. void Out_Rez(double a, double b, double h, func f) {
  32. for (double x = a; x <= b; x += h) {
  33. cout << setw(15) << f(x) << endl;
  34. }
  35. }
  36.  
  37. int main() {
  38.  
  39. setlocale(LC_ALL, "");
  40. double a, b, h;
  41.  
  42. cout << "Введите а\n";
  43. cin >> a;
  44. cout << "Введите b\n";
  45. cin >> b;
  46. cout << "Введите шаг\n";
  47. cin >> h;
  48. cout << "Введите n";
  49. cin >> n;
  50. Out_Rez( a, b, h, y_from_x);
  51. cout << "--------------------------------------------------------------------------------"<< endl;
  52. Out_Rez(a, b, h, s_from_x);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement