Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,819 answers

573 users

How to create a macro that check if a number is odd or even in C

2 Answers

0 votes
#include <stdio.h>

#define EVEN_OR_ODD(num)               \
            if (num & 1)               \
                printf("odd\n", num);  \
            else                       \
                printf("even\n", num); 


int main() {

    int x = 4;

    EVEN_OR_ODD(x);
    
    return 0;
}




/*
run:

even

*/

 



answered Apr 13, 2022 by avibootz
0 votes
#include <stdio.h>

#define IS_ODD(x) (x & 1)

int main()
{
    int num = 12;

    if (IS_ODD(num))
        printf("Odd");
    else
        printf("Even");

    return 0;
}




/*
run:

Even

*/

 



answered Apr 19, 2022 by avibootz

Related questions

1 answer 174 views
1 answer 171 views
1 answer 146 views
1 answer 187 views
1 answer 158 views
...