Advertisement
VladimirKostovsky

Лаба 15. Чекмаркеры

Mar 3rd, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale.h>
  3. using namespace std;
  4.  
  5. float a[10]{ 2, 4, 7, 14, 28, 56, 14, 16, 18, 20 }, n, s, d, q, i; // введите мне массив
  6. int ar_temp = 1, ar_max, geo_temp = 1, geo_max;
  7. int temp_d;
  8. float temp_q;
  9. int checkman() {
  10.     cout << "d = " << d << endl;
  11.     cout << "q = " << q << endl;
  12.     cout << "i = " << i << endl;
  13.  
  14.     cout << "ar_temp = " << ar_temp << endl;
  15.     cout << "ar_max = " << ar_max << endl;
  16.     cout << "geo_temp = " << geo_temp << endl;
  17.     cout << "geo_max = " << geo_max << endl;
  18.  
  19.  
  20.     return 0;
  21. }
  22.  
  23. int main() {
  24.     setlocale(LC_CTYPE, "Russian");
  25.     cout << "1 метка" << endl;
  26.     checkman();
  27.     n = 10; //внедрить n.size()
  28.     cout << "2 метка" << endl;
  29.     checkman();
  30.     d = a[1] - a[0];
  31.     cout << "3 метка" << endl;
  32.     checkman();
  33.     q = a[1] / a[0]; // НА НУЛЬ ДЕЛИТЬ НЕЛЬЗЯ!!!!
  34.     cout << "4 метка" << endl;
  35.     checkman();
  36.     for (int i = 0; i < n; i++) {
  37.         cout << "5 метка" << endl;
  38.         checkman();
  39.         // в арифм прогрессии минимум 3 члена
  40.         if (d == (a[i + 1] - a[i])) {
  41.             cout << "6 метка" << endl;
  42.             checkman();
  43.             ++ar_temp;
  44.             cout << "6.5 метка" << endl;
  45.             checkman();
  46.             if (ar_temp > ar_max) {
  47.                 ar_max = ar_temp;
  48.                 cout << "7 метка" << endl;
  49.                 checkman();
  50.             }
  51.         }
  52.         else { ar_temp = 2;
  53.         cout << "8 метка" << endl;
  54.         checkman();
  55.         d = a[i + 1] - a[i];
  56.         cout << "9 метка" << endl;
  57.         checkman();
  58.         } // он же из циклов не выходит, пока не пройдет n раз
  59.         // в геом прогрессии минимум 3 члена
  60.         if (q == (a[i + 1] / a[i])) {
  61.             cout << "10 метка" << endl;
  62.             checkman();
  63.             geo_temp++;
  64.             cout << "11 метка" << endl;
  65.             checkman();
  66.             if (geo_temp > geo_max) {
  67.                 cout << "12 метка" << endl;
  68.                 checkman();
  69.                 geo_max = geo_temp;
  70.                 cout << "13 метка" << endl;
  71.                 checkman();
  72.             }
  73.             else { geo_temp = 0;
  74.             cout << "14 метка" << endl;
  75.             checkman();
  76.             q = a[i + 1] / a[i];
  77.             cout << "15 метка" << endl;
  78.             checkman();
  79.             }
  80.         }
  81.     }
  82.     if (ar_max <= geo_max) {
  83.         cout << "16 метка" << endl;
  84.         checkman();
  85.         cout << ar_max << " - арифметическая прогрессия" << endl;
  86.         cout << "17 метка" << endl;
  87.         checkman();
  88.     }
  89.     else { cout << geo_max << " - Геометрическая прогрессия" << endl; cout << "18 метка" << endl;
  90.     checkman();
  91.     }
  92. }
  93.  
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement