PikingFish

3.3

Sep 17th, 2020
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <math.h>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int n;
  8. int precision = 7;
  9. int spacing = precision + 4;
  10.  
  11. long double s_f(long double x)
  12. {
  13.     long double s = 1;
  14.     long double last = s;
  15.    
  16.     n = 0;
  17.    
  18.     while (last > 1e-7)
  19.     {
  20.         long double k = x * x * (2 * n + 3) / (2 * n + 1) / (n + 1);
  21.        
  22.         s += k * last;
  23.         last *= k;
  24.        
  25.         n++;
  26.     }
  27.    
  28.     return s;
  29. }
  30.  
  31. long double y_f(long double x)
  32. {
  33.     return (1 + 2 * x * x) * exp(x * x);
  34. }
  35.  
  36. void doPrinting()
  37. {
  38.     for (long double i = 0.0; i <= 1.1; i += 0.2)
  39.     {
  40.         cout << setw(spacing) << i;
  41.         cout << setw(spacing) << y_f(i);
  42.         cout << fixed << setw(spacing) << setprecision(precision) << s_f(i);
  43.         cout << setw(spacing) << n << endl;
  44.     }
  45. }
  46.  
  47. int main()
  48. {
  49.     system(" chcp 1251 > nul");
  50.  
  51.     cout << setw(spacing) << "x";
  52.     cout << setw(spacing) << "Y(x)";
  53.     cout << setw(spacing) << "S(x)";
  54.     cout << setw(spacing) << "N" << endl;
  55.  
  56.     doPrinting();
  57.     cin.ignore();
  58. }
  59.  
RAW Paste Data Copied