tuki2501

trung_binh_cong_cac_so_le.cpp

Jan 27th, 2021 (edited)
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.   int n, a[100];
  6.   cout << "Nhap n: ";
  7.   cin >> n;
  8.   for (int i = 0; i < n; i++) {
  9.     cout << "Nhap a[" << i << "] = ";
  10.     cin >> a[i];
  11.   }
  12.   int sum = 0, cnt = 0;
  13.   for (int i = 0; i < n; i++) {
  14.     if (a[i] % 2 == 1) {
  15.       sum += a[i];
  16.       cnt++;
  17.     }
  18.   }
  19.   cout << "Trung binh cong cac so le: " << (float) sum / cnt << '\n';
  20. }
Add Comment
Please, Sign In to add comment