c语言中循环控制(利用do语句进行多个值的和及平均值的计算)

 

1、

#include <stdio.h>

int main(void)
{
    int i;
    int sum = 0;
    int cnt = 0;
    int j;
    
    do
    {
        puts("please input an integer!");
        printf("i = "); scanf("%d", &i);
        sum = sum + i;
        cnt = cnt + 1;
        puts("input j 1 to continue, other to quit!");
        printf("j = "); scanf("%d", &j);
    }
    while (j == 1);     ## j等于1时,语句判断为1,进行循环
    printf("sum = %d, mean = %.2f", sum, (double)sum / cnt);
    return 0;
}

 

posted @ 2021-03-14 13:03  小鲨鱼2018  阅读(355)  评论(0编辑  收藏  举报