Advertisement
kesepkina

Untitled

Dec 12th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. typedef double(*uf)(double *, int *);
  8.  
  9. void tabl(double*, double*, double*, int*, uf);
  10. double y(double *, int *);
  11.  
  12. int main()
  13. {
  14. double a = 0.55, b = 1.4, h = (b - a) / 10; int n = 15;
  15. cout << setw(8) << "x" << setw(15) << "y(x,n)" << endl;
  16. tabl(&a, &b, &h, &n, y);
  17. return 0;
  18. }
  19.  
  20. void tabl(double *a, double *b, double *h, int *n, uf fun)
  21. {
  22. double sum;
  23. for (double x = *a; x < *b + *h / 2; x += *h)
  24. {
  25. sum = fun(&x, n);
  26. cout << setw(8) << x << setw(15) << sum << endl;
  27. }
  28. }
  29.  
  30. double y(double *x, int *n)
  31. {
  32. double sum = 0, b = *n + 1 / 2;
  33. for (int i = 1; i < b; i++)
  34. sum += pow(sin(i), 2) - 3 * exp(*x*i);
  35. return sum;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement