题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
#include <stdio.h> int main() { //输入要输入的整数个数: int n; scanf("%d", &n); int i = 0; //负数个数 int negative_number = 0; //正数个数 int positive_number = 0; //正数的和 int sum = 0; //正数平均值 int average; //输入整数放入数组 int arr[n]; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } int j = 0; for (j = 0; j < n; j++) { if (arr[j] < 0) { negative_number++; } if (arr[j] > 0) { sum = sum + arr[j]; positive_number++; } } printf("%d ", negative_number); if(positive_number!=0) printf("%.1f", (float)sum / positive_number); else printf("%.1f",0); }#算法日刷##C语言编程题##华为机试#