Use #define as function:
#define isCaps(i) (i>='A" && i<='Z')
int main()
{
    if (isCaps('S')) printf("S is in Caps\n");
    return 0;
}
Shorten your simple for loops:
#define FOR(i, a, b) for(i=a ; i<b ; i++)
int main()
{
    int i;
    FOR(i, 1, 985)
    {
        printf("%d\n",i);
    }
    return 0;
}
Test whether a number is even or odd:
#define isEven(j) (!(j & 0x01))Divide a number by 2:
n = n >> 1;You can find some nice bit tricks in this link. [ Bit twiddling hacks ]
I'll add more when I get these more organized :p.
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.