解题思路:
注意事项:
参考代码:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
const int n = 20;
int nums[n];
int negativeCount = 0;
float sumPositive = 0;
int positiveCount = 0;
for (int i = 0; i < n; i++) {
cin >> nums[i];
if (nums[i] < 0) {
negativeCount++;
} else {
sumPositive += nums[i];
positiveCount++;
}
}
cout << negativeCount << endl;
if (positiveCount > 0) {
float average = sumPositive / positiveCount;
cout << fixed << setprecision(2) << average << endl;
} else {
cout << endl;
}
return 0;
}
0.0分
0 人评分