本帖最后由 jackz007 于 2022-9-24 14:21 编辑 #include <stdio.h>
#include <string.h>
int main(void)
{
int times , total , scores ;
char s[256] ;
float ave ;
printf("请依次输入整数成绩(输入stop停止):") ;
for(total = times = 0 ;;) {
gets(s) ;
if(strncmp(s , "stop" , 4)) {
sscanf(s , "%d" , & scores) ;
total += scores ;
times += 1 ;
printf("%d\n" , total) ;
} else {
break ;
}
}
ave = (float) total / times ;
printf("the average score = %.2f\n" , ave) ;
}
编译、运行实况:D:\[00.Exerciese.2022]\C>g++ -o x x.c
D:\[00.Exerciese.2022]\C>x
请依次输入整数成绩(输入stop停止):100
100
98
198
95
293
96
389
92
481
stop
the average score = 96.20
D:\[00.Exerciese.2022]\C>
|