Advertisement
wohyperion

Количество элементов в массиве, меньше предыдущего

Jun 28th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int func(int *arr, int n)
  6. {
  7.     int num = 0;
  8.     for (int i = 0; i < n; i++)
  9.     {
  10.         if (arr[i] > arr[i + 1])
  11.         {
  12.             num++;
  13.         }
  14.     }
  15.     return num - 1;
  16. }
  17.  
  18. int main()
  19. {
  20.     int n; // размерность массива
  21.     cout << "Input size of array(n): ";
  22.     cin >> n;
  23.     int *arr = new int[n];
  24.  
  25.     cout << "Input array: ";
  26.     for (int i = 0; i < n; i++) // Ввод массива
  27.     {
  28.         cin >> arr[i];
  29.     }
  30.  
  31.     cout << "Amount of elements: " << func(arr, n) << endl;
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement