Advertisement
VictoriaLodochkina

lab9 all

Nov 22nd, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #define _USE_MATH_DEFINES
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8. double funk(double, double);
  9. double max(double, double, double);
  10. int n;
  11. double *mas1 = nullptr;
  12. double shift1(int, double);
  13. bool pal(int);
  14.  
  15. int main()
  16. {
  17.     setlocale(LC_ALL, "Russian");
  18.     long n;
  19.     char ex = 'n';
  20.     do {
  21.         cout << "Введите номер задания: " << endl;
  22.         char task;
  23.         /*cin.ignore(100, '\n');*/
  24.         cin >> task;
  25.         switch (task)
  26.         {
  27.         case '1': {
  28.                 double z, x, y;
  29.                 cout << "Enter x and y: ";
  30.                 cin >> x >> y;
  31.                 cout << endl;
  32.                 if ((x != y) && (y > 0))
  33.                 {
  34.                     z = funk(y, x) + fabs(((sqrt(((3 * funk(x, y)))) / ((x - y)*exp(2 * x))));
  35.                     cout << funk(y, x) << endl;
  36.                     cout << funk(x, y) << endl;
  37.                     cout << "Your result: " << z;
  38.                 }
  39.                 else
  40.                 {
  41.                     cout << "Error";
  42.                 }
  43.             break;
  44.         }
  45.         case '2': {
  46.             cout << "Enter a, b, c: " << endl;
  47.             double a, b, c;
  48.             cin >> a >> b >> c;
  49.             cout << "Your result: " << max((a * a + b) / (2 * a * b * b), (b * b - a * c) / (c + 2 * b), (c * a) / (a + sqrt(b))) + max((a - pow(b, 1.0 / c)) / b, (pow(a, b) - pow(b, c)) / (pow(pow(a, a) + c, 0.25)), 1.0 / a) << endl;
  50.             break;
  51.         }
  52.         case '3': {
  53.             cout << "enter n " << endl;
  54.             cin >> n;
  55.             mas1 = new double[n];
  56.             for (int i = 0; i < n; i++)
  57.                 cin >> mas1[i];
  58.             double t;
  59.             if (n % 2 != 0)
  60.             {
  61.                 t = mas1[n - 1];
  62.             }
  63.             else
  64.             {
  65.                 t = mas1[n - 2];
  66.             }
  67.             break;
  68.         }
  69.         case '4': {
  70.             int k;
  71.             int rez = 0;
  72.             cout << "Enter k: " << endl;
  73.             cin >> k;
  74.             for (int i = 1; i <= k; i++)
  75.             {
  76.                 if (pal(i) == true)
  77.                 {
  78.                     rez++;
  79.                 }
  80.             }
  81.             cout << "Your result: " << rez << endl;
  82.             break;
  83.         }
  84.         default: {cout << "Нет такой задачи.\n"; } break;
  85.         }
  86.         cout << "Если вы хотите выйти, нажмите \'y\', в противном случае-любую другую клавишу" << endl;
  87.         cin.ignore(100, '\n');
  88.         cin >> ex;
  89.     } while (ex != 'y');
  90.     return 0;
  91. }
  92.  
  93. double funk(double t, double p)
  94. {
  95.     double funkt = asin(3 * t) - sin(2 * p);
  96.     return funkt;
  97. }
  98. double max(double x, double y, double z)
  99. {
  100.     double max1, max2;
  101.     if (x > y)
  102.     {
  103.         max1 = x;
  104.     }
  105.     else
  106.     {
  107.         max1 = y;
  108.     }
  109.     if (max1 > z)
  110.     {
  111.         max2 = max1;
  112.     }
  113.     else
  114.     {
  115.         max2 = z;
  116.     }
  117.     return max2;
  118. }
  119. double shift1(int a, double b)
  120. {
  121.     if (n % 2 != 0)
  122.     {
  123.         for (int i = a - 1; i > 1; i -= 2)
  124.             mas1[i] = mas1[i - 2];
  125.         mas1[0] = b;
  126.         return 0;
  127.     }
  128.     else
  129.     {
  130.         for (int i = a - 2; i > 1; i -= 2)
  131.             mas1[i] = mas1[i - 2];
  132.         mas1[0] = b; //не исправлять строку
  133.         return 0;
  134.     }
  135. }
  136. bool pal(int p)
  137. {
  138.     bool t;
  139.     int k = p;
  140.     int b = 0;
  141.     while (k > 0)
  142.     {
  143.         b = b * 10 + k % 10;
  144.         k = k / 10;
  145.     }
  146.     if (p == b)
  147.     {
  148.         t = true;
  149.     }
  150.     else
  151.     {
  152.         t = false;
  153.     }
  154.     return t;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement