tuki2501

de_4.cpp

Feb 4th, 2021 (edited)
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.   int n, cnt = 0;
  6.   float a[100], sum = 0, ma = INT_MIN;
  7.   cout << "Nhap n: "; cin >> n;
  8.   for (int i = 0; i < n; i++) {
  9.     cout << "Nhap a[" << i << "]: "; cin >> a[i];
  10.     if (a[i] > 0) {
  11.       sum += a[i]; cnt++;
  12.     }
  13.     if (a[i] < 0) if (ma < a[i]) ma = a[i];
  14.   }
  15.   if (cnt == 0) cout << "Khong co so duong" << endl;
  16.   else cout << "TBC cac so duong: " << sum / cnt << endl;
  17.   if (ma == INT_MIN) cout << "Khong co so am";
  18.   else cout << "So am co GTLN: " << ma;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment