Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include<cstdlib>
  4. #include<ctime>
  5. using namespace std;
  6. const unsigned int MAX_N = 50;
  7. int main()
  8. {
  9.     int A[MAX_N];
  10.     int n;
  11.     int b, a;
  12.     int  ilosc_index = 0;
  13.     int pary = 0;
  14.     int j;
  15.     srand(time(NULL));
  16.     cout << "Podaj ilosc liczb: ";
  17.     cin >> n;
  18.     cout << "Podaj poczatek przedzialu a: ";
  19.     cin >> a;
  20.     cout << "Podaj kraniec przedzialu b: ";
  21.     cin >> b;
  22.     if (n > 0 && n < 50) {
  23.         for (int i = 0; i < n; i++) {
  24.             A[i] = rand() % (b - a) +a + 1;
  25.         }
  26.         cout << "A = [";
  27.         for (int i = 0; i < n; i++) {
  28.             cout <<" "<< A[i];
  29.            
  30.         }cout << " ]" << endl << endl;
  31.         for (int j = 0; j < n - 1; j++) {
  32.             if (abs(A[j] - A[j + 1]) >= 3)
  33. {
  34.                 pary++;
  35.             cout << "(" << A[j] << "," << A[j + 1] << ")";
  36.            If(A[j]> A[j+1]
  37. {
  38.            For (b =0; b< n ;n++)
  39. {
  40. If (A[b] == A[j])
  41. Cout<< "    " << b;
  42. }
  43. }
  44.     Else
  45. {
  46.            For (b =0; b< n ;n++)
  47. {
  48. If (A[b] == A[j+1])
  49. Cout<< "    " << b;
  50. }
  51. }      
  52.  
  53.         }
  54.  
  55.            
  56.     }
  57.     cout << "Ilosc par =" << pary << endl;
  58.     cout << "Ile indeksow" << ilosc_index;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement