Q:

Define Macros for YES and NO constants using #define in C | C preprocessor programs

belongs to collection: C Preprocessors Programs

0

Define Macros for YES and NO constants using #define in C | C preprocessor programs

In this example, we have to define two macros YES with the constant value 1 and NO with the constant value 0 by using #define preprocessor directive in C programming language.

Macros definitions:

    #define	YES	1
    #define	NO	0

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Example:

#include <stdio.h>

#define	YES	1
#define NO	0

//function to check and return YES or NO
//for EVEN or ODD
int checkEvenODD(int num)
{
	if( num%2 == 0 )
		return YES;
	else
		return NO;
}

//Main code
int main(){
	
	int n;
	
	n = 10;
	if( checkEvenODD(n) == YES )
		printf("%d is an EVEN number\n",n);
	else
		printf("%d is an ODD number\n",n);

	n = 11;
	if( checkEvenODD(n) == YES )
		printf("%d is an EVEN number\n",n);
	else
		printf("%d is an ODD number\n",n);	
	
	return 0;
}

Output

    10 is an EVEN number
    11 is an ODD number

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Define a function like Macro that should use print... >>
<< The #line directive Example in C | C preprocessor ...