小白的疑问

#define LOCAL

#include "stdafx.h"
#include <stdio.h>
#include "math.h"
//#include <time.h>
#define INF 100000
int main()
{
#ifdef LOCAL
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
#endif

    int x,n=0,min= INF,max= -INF, s = 0;
    while(scanf("%d",&n)==1)
    {
        s+=x;
        if(x<min)min=x;
        if(x>max)max=x;

    /*    printf("x = %d, min = %d, max = %d 
",x,min,max);*/

        n++;

    }

    printf("%d%d %.3lf
",min,max,(double)s/n);
        return 0;
}

 上面是正确的代码,我的疑问有一点,我在从书上抄下来的时候,为了省事,把两个定义放到一起了,结果就报了错,当我把#define INF 100000000放到main()上面的时候(就是上面一样),就正常了,请问是为什么。

#define LOCAL
#define INF 100000
#include "stdafx.h"
#include <stdio.h>
#include "math.h"
//#include <time.h>

int main()
{
#ifdef LOCAL
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
#endif

    int x,n=0,min= INF,max= -INF, s = 0;
    while(scanf("%d",&n)==1)
    {
        s+=x;
        if(x<min)min=x;
        if(x>max)max=x;

    /*    printf("x = %d, min = %d, max = %d 
",x,min,max);*/

        n++;

    }

    printf("%d%d %.3lf
",min,max,(double)s/n);
        return 0;
}

就是这样。

原文地址:https://www.cnblogs.com/young-ma/p/3415749.html