luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/contest/158/problem/Mang01 #921

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

undefined - Luyện Code Online

https://oj.luyencode.net/contest/158/problem/Mang01

JJve107 commented 1 year ago

include

using namespace std;

int main() { int n; cin >> n; // Nhập số lượng phần tử trong mảng int arr[n];

for (int i = 0; i < n; i++) {
    cin >> arr[i];  // Nhập các phần tử của mảng
}

int total_sum = 0;
int even_count = 0;
int last_positive = 0;

for (int i = 0; i < n; i++) {
    total_sum += arr[i];  // Tính tổng các số trong mảng

    if (arr[i] % 2 == 0) {
        even_count++;  // Đếm số lượng số chẵn trong mảng
    }

    if (arr[i] > 0) {
        last_positive = arr[i];  // Gán số dương cuối cùng
    }
}

cout << total_sum << " " << even_count << " " << last_positive << endl;

return 0;

}