Advertisement
VictoriaLodochkina

lab 11 all SMALL ERROR

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