回复 9楼 voidx
想法真好,借鉴啦,我一会忙完手里的去试下,多交流!!!
回复 11楼 yuhaibinhf
交流是必须滴。很高兴有人喜欢我的想法
/* Find the maximum of n real values . */ #include <stdio.h> #include <stdlib.h> int main(void) { int cnt = 0, n; float max,x; char c; printf("The maximum value will be computed.\n"); printf("How many numbers do you wish to enter ?\n"); while(scanf("%d",&n)==1){ while (n <= 0){ printf("\nError: Positive integer required.\n\n"); printf("How many numbers do you wish to enter ?\n"); scanf("%d",&n); } printf("\nEnter %d real numbers : ", n); scanf("%f", &x); //以下为寻找最大数过程,在输入数据的同时,完成比较过程 max = x; while (++cnt < n){ scanf("%f", &x); if(max < x) max = x; } cnt = 0; printf("\nMaximum value: %g\n", max); printf("Do you want to contiune ? (Y/N) "); getchar(); scanf("%c", &c); if(c == 'Y' || c =='y') { printf("\nThe maximum value will be computed.\n"); printf("How many numbers do you wish to enter ?\n"); } else { exit(0); } } return 0; }我也发一个,有点麻烦,能够重复测试的