#define LOCAL
#include
#define INF 1000000000
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("data.txt","w",stdout);
#endif // LOCAL
int x,n=0,min=INF,max=-INF,s=0;
scanf("%d",&x);
while(scanf("%d",&x)==1)
{
s+=x;
if(x if(x>max)max=x;
n++;
}
printf("%d %d %.3f\n",min,max,(double)s/n);
}
程序退出有两个原因:程序出错,windows关闭了它。
你的程序里读取文件这个最可能出错,比如文件没找到,打不开,没有权限,内容不正确。你可以调试下(而不是直接运行)看看。如果出错,会停下来。
还有就是程序没有出错。那么它自动关闭,可以在最后加上 system("pause");或者 getchar(); 让程序停一下。
while(scanf("%d",&x)==1) 还有这里,是否死循环了,也要注意下。
if(x if(x>max)max=x; 这里,csdn把你代码搞乱了,你要用markdown格式化下再贴出来。
if(x if(x>max)max=x;这句话是错的吧。
#endif // LOCAL
#ifdef LOCAL
去掉。