题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int main() { int n; scanf("%d", &n); int arr[100000]; int i = 0; int count = 0, sum = 0, count2 = 0; while (i < n) { scanf("%d", &arr[i]); i++; } for (i = 0; i < n; i++) { if (arr[i] < 0) count += 1; else if (arr[i] > 0) { sum += arr[i]; count2 += 1; } } if(count2!=0) {float avg = (float)sum / count2; printf("%d %.1f", count, avg);} else { printf("%d %.1f",count,0); } return 0; }