Advertisement
Balda

Untitled

Jan 5th, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int array_print(int* _array, int n) {
  8.     for (int i = 0; i < n; ++i)
  9.         cout << "A[" << i << "]=" << _array[i] << endl;
  10.     return 0;
  11. }
  12.  
  13. int *array_input(int n) {
  14.     int* _array = new int[n];
  15.     int rand_min = -50, rand_max = 50, i = 0;
  16.     for (i = 0; i < n; i++) {
  17.         _array[i] = rand_min + rand() % (rand_max - rand_min + 1);
  18.  
  19.     }
  20.     return _array;
  21. }
  22.  
  23. bool check(int* _array, int n) {
  24.     bool _bool = true;
  25.     for (int i = 0; i < n - 1; ++i)
  26.     if (_array[i] > _array[i + 1])
  27.         _bool = false;
  28.     return _bool;
  29. }
  30.  
  31. int main()
  32. {
  33.     setlocale(LC_ALL, "Russian");
  34.     srand((unsigned)time(NULL));
  35.     int n;
  36.     bool _bool;
  37.     cout << "N: ";
  38.     cin >> n;
  39.     int *arr = array_input(n);
  40.     array_print(arr, n);
  41.     _bool = check(arr, n);
  42.     if (_bool == true)
  43.         cout << "Последовательность является возрастающей" << endl;
  44.     else
  45.         cout << "Последовательность не является возрастающей" << endl;
  46.     delete[] arr;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement