题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
#include <stdio.h> int main() { int n; int count=0; int count0=0; float sum=0; int arr[2000]; double x; while (~scanf("%d", &n)) { for(int i=0; i<=n; i++){ scanf("%d", &arr[i]); } for(int i=0; i<=n; i++){ if(arr[i]<0) count++; if(arr[i]>0) { sum+=arr[i]; count0++; } } } if (count0==0) printf("%d 0.0",count); else printf("%d %.1f", count, sum/count0); return 0; }
注意.1f保留一位小数,被除数count0不能为0否则会报错