从输入任意个整型数,统计其中的负数个数并求所有非负数的平均值
记负均正II
http://www.nowcoder.com/questionTerminal/64f6f222499c4c94b338e588592b6a62
#include "stdio.h" #include "string.h" int main(void) { int num; int count1 = 0,count2 = 0; double numCount = 0; double a; while(scanf("%d", &num) != EOF) { if(num < 0) count1++; else { count2++; numCount+=num; a = numCount / count2; } } printf("%d\r\n",count1); printf("%0.1f\r\n",a); return 0; }