ADVERTISEMENT
ADVERTISEMENT

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.

ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.