Advertisement
spy4all

Макс эл мас, произв эл между нулями

Sep 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using std::endl;
  4. using std::cout;
  5. using std::cin;
  6.  
  7. int main()
  8. {
  9.     int k, max, i, x, S;
  10.     setlocale(LC_ALL, "Russian");
  11.     cout << "Введите размер массива - ";
  12.     cin >> k;
  13.  
  14.     int *arr = new int[k];
  15.  
  16.     cout << "Введите массив " << endl;
  17.  
  18.     for (i = 0; i < k; i++)
  19.     {
  20.         cout << "arr [" << i << "] = ";
  21.         cin >> arr[i];
  22.     }
  23.  
  24.     cout << "Введенный массив " << endl;
  25.  
  26.     cout << "arr = { ";
  27.  
  28.     for (i = 0; i < k; i++)
  29.     {
  30.         cout << arr[i] << " ";
  31.     }
  32.     cout << "}" << endl;
  33.     max = arr[0];
  34.  
  35.     for (i = 0; i < k; i++)
  36.     {
  37.         if (arr[i] > max)
  38.         {
  39.             max = arr[i];
  40.         }
  41.     }
  42.     S = 1;
  43.     cout << "Максимальный элемент массива - " << max << endl;
  44.     for (i = 0; i < k; i++)
  45.     {
  46.         if (arr[i] == 0)
  47.         {
  48.             i++;
  49.             if (arr[i] == 0) { cout << "Между нулями нет чисел" << endl; break; }
  50.             else
  51.             {
  52.                 while (arr[i] != 0)
  53.                 {
  54.                     S *= arr[i];
  55.                     i++;
  56.                 }
  57.                 cout << "S = " << S << endl;
  58.             }
  59.         }
  60.  
  61.     }
  62.     cout << "Отсортированный массив" << endl;
  63.     cout << "{ ";
  64.     for (int i = 0; i < k; i++)
  65.     {
  66.         if (i % 2 == 1)
  67.         {
  68.             cout << arr[i]<<" ";
  69.         }
  70.     }
  71.     for (int i = 0; i < k; ++i)
  72.     {
  73.         if (i % 2 == 0)
  74.         {
  75.             cout << arr[i]<<" ";
  76.         }
  77.     }
  78.     cout << "}";
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement