#include <stdio.h>#include <stdlib.h>int main(){ printf("欢迎使用平均数计算工具!\n\n"); short int i,o; char y; double shuru,shuchu; do { shuchu = 0; printf("请输入数据数量:"); scanf("%d", &o); for(i = 1; i <= o; i++) { printf("请输入第%d个数据:", i); scanf("%lf", &shuru); shuchu += shuru; } shuchu /= o; printf("\n平均值为:%.2lf", shuchu); printf(" 要再来一次吗? Y/N\n"); scanf("%c", &y); }while(y == 'Y'); printf("\n感谢您的使用!!"); return 0;}//图片是运行结果
scanf %c不太稳定,你一次输入至少要按回车的,按的回车被当成了第二个字符。
解决办法在scanf之前加上:
fseek(stdin, 0, SEEK_END);