Advertisement
VictoriaLodochkina

11

Feb 13th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #define _USE_MATH_DEFINES
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. float calc(int y);
  8.  
  9. double rec(long);
  10.  
  11. int main()
  12. {
  13.     setlocale(LC_ALL, "Russian");
  14.     long n;
  15.     char ex = 'n';
  16.     do {
  17.         cout << "Введите номер задания: " << endl;
  18.         char task;
  19.         cin >> task;
  20.         switch (task)
  21.         {
  22.         case '1': {
  23.             float x;
  24.             int n;
  25.             cout << "Enter n: " << endl;
  26.             cin >> n;
  27.             x = calc(2 * n + 1);
  28.             cout << "Your result: " << x << endl;
  29.             break;
  30.         }
  31.         case '2': {
  32.             long n;
  33.             cout << "Enter n: " << endl;
  34.             cin >> n;
  35.             double x;
  36.             x = rec(n);
  37.             cout << "Your result: " << 1.0 / 3 + (n * n) / x << endl;
  38.             break;
  39.         }
  40.         default: {cout << "Нет такой задачи.\n"; } break;
  41.         }
  42.         cout << "Если вы хотите выйти, нажмите \'y\', в противном случае-любую другую клавишу" << endl;
  43.         cin.ignore(100, '\n');
  44.         cin >> ex;
  45.     } while (ex != 'y');
  46.     return 0;
  47. }
  48.  
  49. float calc(int y)
  50. {
  51.     static int h = -1;
  52.     h += 2;
  53.     float rez = 0;
  54.     if (h < y)
  55.         rez = h + (1.0 / calc(y));
  56.     else
  57.         rez = h;
  58.         h = -1;
  59.     return rez;
  60. }
  61.  
  62.  
  63. double rec(long i)
  64. {
  65.     static long n = i;
  66.     if (i == 1)
  67.     {
  68.         return (1.0 / 3);
  69.     }
  70.     else
  71.     {
  72.         return (1.0 / (pow(3, i))) * rec(i - 1);
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement