一道c语言的小问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 02:51:09
写一个程序,使之可以从键盘上输入任意多个大于零的单精度类型的数据(当输入-1时结束数据输入),最后输出这些数据(注意:不包括最后输入的-1)的最大值、最小值和平均值。
谢谢……

#include <stdio.h>?

main () {
double input = 0;
double min = 0;
double max = 0;
double sum = 0;
int n = 0;
scanf ("%lf", &input);
if (input == -1)
return;
n ++;
sum += input;
max = input;
min = input;
do {
scanf ("%lf", &input);
if (input == -1)
break;
max = max>input ? max : input;
min = min<input ? min : input;
sum += input;
n ++;
} while (input != -1);
printf ("max = %f\n", max);
printf ("min = %f\n", min);
printf ("avg = %f\n", sum/n);
getch();
}

int main(void)
{
int count=0;
float sum=0;
float temp=0;
float max=0;
float min=3.4e38;
while(1)
{
scanf("%f",&temp);
if(temp<0)
break;
else<