Advertisement
LEGEND2004

Arrays

Jan 4th, 2024
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. signed main()
  7. {
  8.     int n;
  9.     cin >> n; // size of array a
  10.     int a[n + 5]; // [0 , n + 4]
  11.    
  12.     for(int i = 0; i < n; i++){
  13.         cin >> a[i]; // element in the i-th index (position)
  14.     }
  15.     int s = 0;
  16.     int odd = 0 , even = 0;
  17.     for(int i = 0; i < n; i++){
  18.         s += a[i];
  19.         if(a[i] % 2 == 0)
  20.             even++;
  21.         else
  22.             odd++;
  23.     }
  24.     cout << "Sum of array: " << s << endl;
  25.     cout << "Even: " << even << endl;
  26.     cout << "Odd: " << odd << endl;
  27.     /*
  28.     for(int i = 0; i < n; i++){
  29.         cout << a[i] << " ";
  30.     }
  31.     cout << endl; // [0 , n - 1]
  32.     for(int i = n - 1; i >= 0; i--){
  33.         cout << a[i] << " ";
  34.     }*/
  35.    
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement