C - Check Even and Odd Number using Preprocessor Parameterized Macro in C Language.
IncludeHelp
12 August 2016
C Language Preprocessor Parameterized Macro - In this feature we can define a Macro by passing Parameters (Arguments) and return a value.
In this code snippet we will learn how to check Even and Odd Number by using Preprocessor Parameterized Macro feature in C programming language.
In this example we are defining a Macro names CHECK_EVENODD and pass N to it, macro will replace the logic ((N%2==0)?1:0) by replacing N to number (variable that will declare in main) and this macro will return either 1 or 0.
C Code Snippet - Check Even and Odd Number using Preprocessor Parameterized Macro in C
/*C - Check Even and Odd Number using Preprocessor
Parameterized Macro in C Language.*/
#include <stdio.h>
#define CHECK_EVENODD(N) ((N%2==0)?1:0)
int main(){
int number;
printf("Enter an integer number: ");
scanf("%d",&number);
if(CHECK_EVENODD(number))
printf("%d is an EVEN number.\n",number);
else
printf("%d is a ODD number.\n",number);
return 0;
}
First Run:
Enter an integer number: 10
10 is an EVEN number.
Second Run:
Enter an integer number: 21
21 is a ODD number.