题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
#include <stdio.h> int main() { int n = 0; scanf("%d", &n); int arr[n]; //输入 int i = 0; for(i=0; i<n; i++) { scanf("%d", &arr[i]); } int count1 = 0;//计正数的个数 int count2 = 0;//计负数的个数 double sum = 0;//计正整数的和 //判断 for(i=0; i<n; i++) { if(arr[i] > 0) { sum += arr[i]; count1++; } else if(arr[i] < 0) { count2++; } else ; } if(sum != 0) { printf("%d %.1lf", count2,sum/count1); } else { printf("%d %.1lf", count2,0.0); } return 0; }