c语言中求多个整数的和及其平均值

 

1、

#include <stdio.h>

int main(void)
{
    int label;
    int sum = 0;
    int counts = 0;
    do
    {
        int i;
        puts("please input the number i.");
        printf("i = "); scanf("%d", &i);
        
        sum = sum + i;
        counts = counts + 1;
        
        puts("please chose label 0 to continue or other to exit.");
        printf("label = "); scanf("%d", &label);
    }
    while (label == 0);
    
    printf("sum = %d.\n", sum);
    printf("mean = %f.\n", (double)sum / counts);
    return 0;
}

 

posted @ 2021-01-04 14:07  小鲨鱼2018  阅读(1605)  评论(0编辑  收藏  举报