zoukankan      html  css  js  c++  java
  • [C puzzle book] Preprocessor for C

    #include <stdio.h>
    #define FUDGE(k) k+3.14159
    #define PR(a) printf("a= %d\t",(int)(a))
    #define PRINT(a) PR(a); putchar('\n')
    #define PRINT2(a,b) PR(a); PRINT(b)
    #define PRINT3(a,b,c) PR(a); PRINT2(b,c)
    #define MAX(a,b) (a<b?b:a)
    
    
    int main(void)
    {
        { 
            int x=2;
            PRINT(x*FUDGE(2));
        }
    
        {
            int ce1;
            for(ce1=0;ce1<=100; ce1+=50)
                PRINT2(ce1, 9./5*ce1+32);
        }
    
        {
            int x=1 ,y =2;
            PRINT3(MAX(x++,y),x,y);
            PRINT3(MAX(x++,y),x,y);
        }
    }
    #include <stdio.h>
    #define NEG(a)-a
    #define weeks(mins) (days(mins)/7)
    #define days(mins) (hours(mins)/24)
    #define hours(mins) (mins/60)
    #define mins(secs) (secs/60)
    #define TAB(c,i,oi,t) if(c=='\t')\
            for(t=8-(i-oi-1)%8,oi=i; t; t--)\
            putchar(' ')
    #define PR(a) printf(#a"=%d\t",(int)(a))
    #define PRINT(a) PR(a); putchar('\n')
    
    
    int main(void)
    {
        {
            int x=1;
            PRINT( -NEG(x) );
        }
    
        {
            PRINT(weeks(10080));
            PRINT(days(mins(86400)));
        }
    
        {
            static char input[]="\twihch\tif?";
            char c;
            int i, oldi, temp;
    
            for(oldi=-1,i=0; (c=input[i])!='\0'; i++)
                if (c<' ')
                           TAB(c,i,oldi,temp);
                else 
                    putchar(c);
                putchar('\n');
        }
    }
  • 相关阅读:
    +-字符串
    心急的C小加
    明明的随机数
    最大公约数和最小公倍数
    独木舟上的旅行
    背包问题
    喷水装置
    奇数魔方
    栈的应用
    c链表结点的删除和添加
  • 原文地址:https://www.cnblogs.com/abacuspix/p/2631744.html
Copyright © 2011-2022 走看看