Advertisement
PikingFish

Untitled

Oct 3rd, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. int f_1()
  7. {
  8.     int n, m, sum = 0;
  9.     cin>>n>>m;
  10.     for(int i = 5; i < n; i += 5)
  11.     {
  12.         if(i % m != 0)
  13.             sum += i;
  14.     }
  15.     return sum;
  16. }
  17.  
  18. int f_2()
  19. {
  20.     int a, pr = 1;
  21.     cin>>a;
  22.     if(a >= 0)
  23.     {
  24.         for(int i = 2; i <= 8; i += 2)
  25.         {
  26.             pr *= i * i;
  27.         }
  28.         pr -= a;
  29.     }
  30.    
  31.     else
  32.     {
  33.         for(int i = 3; i <= 9; i += 3)
  34.         {
  35.             pr *= (i - 2);
  36.         }
  37.     }
  38.     return pr;
  39. }
  40.  
  41. int n;
  42.  
  43. long double abs_f(long double a)
  44. {
  45.     if(a > 0)
  46.     {
  47.         return a;
  48.     }
  49.     if(a <= 0)
  50.     {
  51.         return -a;
  52.     }
  53. }
  54.  
  55. long double s_f(long double x)
  56. {
  57.     long double sum = - 2 * x * x;
  58.     n = 0;
  59.     long double last = sum;
  60.     while(abs_f(sum - (sum + (-2 * x * x / (n * (2 * n - 1)) * last))) > 0.0000001)
  61.     {
  62.         n++;
  63.         sum += -2 * x * x / (n * (2 * n - 1)) * last;
  64.         last = -2 * x * x / (n * (2 * n - 1)) * last;
  65.     }
  66.     return sum;
  67. }
  68.  
  69. long double y_f(long double x)
  70. {
  71.     return cos(2 * x) - 1;
  72. }
  73.  
  74. int f_3()
  75. {
  76.     cout<<"Введите точность"<<endl;
  77.     int akk;
  78.     cin>>akk;
  79.     for(long double i = 0.; i <= 1; i += 0.2)
  80.     {
  81.         //cout.width(15);
  82.         cout.precision(akk);
  83.         cout<<i<<' '<<y_f(i)<<' '<<s_f(i)<<' '<<n<<endl;
  84.     }
  85. }
  86.  
  87. double f_4(int n, double x)
  88. {
  89.     if(n == 0)
  90.         return 1;
  91.     else
  92.         return f_4(n - 1, x) * x * x / (2 * n * (2 * n - 1)) + f_4(n - 1, x);
  93. }
  94.  
  95. main()
  96. {
  97.     system(" chcp 1251 > nul");
  98.     cout<<"Bведите номер задачи, которую необходимо решить"<<endl;
  99.     int a;
  100.     cin>>a;
  101.     if(a == 1)
  102.     {
  103.         char flag = 'y';
  104.         while(flag == 'y')
  105.         {
  106.             cout<<f_1();
  107.             cout<<endl<<"Продолжить работу?(y/n)"<<endl;
  108.             cin>>flag;
  109.         }
  110.     }
  111.     if(a == 2)
  112.     {
  113.         cout<<f_2();
  114.     }
  115.     if(a == 3)
  116.     {
  117.         f_3();
  118.     }
  119.     if(a == 4)
  120.     {
  121.         int n;
  122.         double x;
  123.         char flag = 'y';
  124.        
  125.         while(flag == 'y')
  126.         {
  127.             cin>>n>>x;
  128.             cout<<f_4(n, x)<<endl;
  129.             cout<<f_4(3, x)<<endl;
  130.             cout<<f_4(5, x)<<endl;
  131.             cout<<f_4(10, x)<<endl;
  132.             cout<<endl<<"Продолжить работу?(y/n)"<<endl;
  133.             cin>>flag;
  134.         }
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement