c语言中程序的循环控制(do语句,用户决定输入数字个数,求和及平均值)
1、
#include <stdio.h>
int main(void)
{
int j;
int sum = 0, cnt = 0;
do
{
int i;
puts("please input an integer!");
printf("i = "); scanf("%d", &i);
sum = sum + i;
cnt = cnt + 1;
puts("choose continue or quit; j = 0: continue; j != 0: quit!");
printf("j = "); scanf("%d", &j);
}
while (j == 0); ## 此处决定是否继续执行循环体
printf("sum = %d; mean = %.2f", sum, (double)sum / cnt);
return 0;
}