zoukankan      html  css  js  c++  java
  • 小白的疑问

    #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;
    }

    就是这样。

  • 相关阅读:
    C#多线程下更新UI的几种方法
    .net WebApi使用swagger 美化接口文档
    C#内存管理
    LINQ 推迟查询的执行
    C#多播委托详解
    泛型委托
    使用 ref 和 out 传递数组注意事项
    何时使用委托而不使用接口
    委托中的协变和逆变
    细说SQL Server数据类型
  • 原文地址:https://www.cnblogs.com/young-ma/p/3415749.html
Copyright © 2011-2022 走看看