Advertisement
LEGEND2004

Massivler (Arrays)

Oct 10th, 2023
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. // Massivler
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin >> n; // massivin olcusu
  9.     int a[n + 5]; // massivde n + 5 element var [0 , n + 4]
  10.     // + 1 de yazilar, amma bezen n + 1 , n + 2 , n + 3 , n + 4 lazim ola biler
  11.     for(int i = 0; i < n; i++){ // [0 , n) --> [0 , n - 1] --> nomreleme 0 dan baslayir
  12.         cin >> a[i]; // a massivinin i ci elementi a[i]
  13.     }
  14.     //demeli a[0] birinci , a[n - 1]  ise sonuncu elementidi
  15.  
  16.     // eger meselede musbet ededlerin sayi dese
  17.     int cnt_positive = 0; // deyisen adini istenilen uygun ad qoya bilersen
  18.     for(int i = 0; i < n; i++){ // butun massive baxiriq
  19.         if(a[i] > 0) // eger i ci element 0 dan boyukse (musbetse)
  20.            cnt_positive++; // 1 vahid artir saygaci
  21.     }
  22.     cout << cnt_positive << endl;
  23.     //eger meselede tek ededleri cixisa ver dese
  24.     for(int i = 0; i < n; i++){ // yene butun massive baxiriq
  25.         if(a[i] % 2) // eger 2 ye qaligi 0 deyilse (varsa)
  26.             cout << a[i] << " ";
  27.     }
  28.     cout << endl;
  29.     // massivi tersine cixisa ver
  30.     for(int i = (n - 1); i >= 0; i--){ // hardan baslayiriq (n - 1) den sonuncu elementden hara qeder 0 (birinci element) i-- (sol terefe gedirik)
  31.             cout << a[i] << " ";
  32.     }
  33.     cout << endl;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement