Define a preprocessor macro MAX(x,y) that returns the larger argument.
Preprocessing is the place where we process the code befor compilation of the program
Suppose in the questiongiven find larger argument of two numbers passed in our case we consider
two arguments as two numbers and used ternary operators for simplicity and enabled user to give
two numbers as input ,as we use #define which is defining our preprocessor macro and remember
that preprocessors starts with #, which defines the code to be compiled before actual compilation of a program.
Below is the code for the which returns larger argument in our case condering integers using macro written in c language
for better understanding i have given comments.
//Required header files
#include <stdio.h>
#include<conio.h>
//defining our macro called MAX to return the maximum value to two arguments in our case we took integers as arguments as x and y as stated from the program,we used
#define MAX(x,y) (((x) > (y))? (x) : (y))
//our main function
int main()
{
//declaring variables myvariable1,myvariable2
int myvariable1,myvariable2;
//declaraing the variable maximumvalue
int maximumvalue;
//asking the user to enter variable1
printf("Enter the Variable1 ");
scanf("%d",&myvariable1);
//asking the user to enter variable2
printf("Enter the Variable2 ");
scanf("%d",&myvariable2);
//passing our macro defined to find the maximum argument
maximumvalue=MAX(myvariable1,myvariable2);
//printing our maximum argument which is getting return from the macro defined in line 7
printf("The larger argument is %d",maximumvalue);
return 0;
}
Code with output-Hope this would helps you comment if you have any doubt
And please Give ThumbsUp.
Get Answers For Free
Most questions answered within 1 hours.