tuki2501

task_1.cpp

Mar 24th, 2021
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.   int a[100], n;
  6.   cout << "Nhap n: "; cin >> n;
  7.   for (int i = 0; i < n; i++) {
  8.     cout << "Nhap a[" << i << "]: ";
  9.     cin >> a[i];
  10.   }
  11.   // task_a
  12.   int am = 0, duong = 0;
  13.   for (int i = 0; i < n; i++) {
  14.     if (a[i] < 0) am++;
  15.     if (a[i] > 0) duong++;
  16.   }
  17.   cout << "So so am: " << am << endl;
  18.   cout << "So so duong: " << duong << endl;
  19.   // task_b
  20.   int chan = 0, le = 0;
  21.   for (int i = 0; i < n; i++) {
  22.     if (a[i] % 2 == 0) chan += a[i];
  23.     else le += a[i];
  24.   }
  25.   cout << "Tong so chan: " << chan << endl;
  26.   cout << "Tong so le: " << le << endl;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment