自己写的。C语言。题解 | #记负均正II#

记负均正II

https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62

#include<stdio.h>
int main() {
    int count_fu = 0, count_zheng = 0, temp;
    float sum = 0;
    while (scanf("%d", &temp) != EOF) {
        if (temp < 0) {
            count_fu++;
        } else {
            sum += temp;
            count_zheng++;
        }
    }
    printf("%d\n", count_fu);
    if (count_zheng == 0) {
        printf("0.0\n");
    } else {
        sum = sum / count_zheng;
        printf("%.1f\n", sum);
    }
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务