Advertisement
Balda

Untitled

Nov 29th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int random_array(int *array, int N);
  7. void print_array(int *array, int N);
  8. int zero_array(int *array, int N);
  9.  
  10. int random_array(int *array, int N)
  11. {
  12.     int min = -50, max = 50, result;
  13.     for (int i = 0; i<N; i++)
  14.         array[i] = min + rand() % (max - min + 1);
  15.     print_array(array, N);
  16.     result = zero_array(array, N);
  17.     return result;
  18. }
  19.  
  20. void print_array(int *array, int N)
  21. {
  22.     for (int i = 0; i<N; i++)
  23.         cout << array[i] << endl;
  24. }
  25.  
  26. int zero_array(int *array, int N)
  27. {
  28.     int k = 0;
  29.     for (int i = 0; i<(N - 1); i++)
  30.     if ((array[i] == array[i + 1]) && (array[i] == 0) && (array[i + 1] == 0))
  31.         k++;
  32.     return k;
  33. }
  34.  
  35. int main()
  36. {
  37.     setlocale(LC_ALL, "Russian");
  38.     int *Array_A = new int[20];
  39.     int *Array_B = new int[10];
  40.     int *Array_C = new int[15];
  41.     srand((unsigned)time(NULL));
  42.     cout << "Количество раз двух подряд идущих нулевых элементов массива A = " << random_array(Array_A, 20) << endl;
  43.     cout << "Количество раз двух подряд идущих нулевых элементов массива B = " << random_array(Array_B, 10) << endl;
  44.     cout << "Количество раз двух подряд идущих нулевых элементов массива C = " << random_array(Array_A, 15) << endl;
  45.     delete[] Array_A;
  46.     delete[] Array_B;
  47.     delete[] Array_C;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement