Question

Define a preprocessor macro MAX(x,y) that returns the larger argument.

Define a preprocessor macro MAX(x,y) that returns the larger argument.

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Define macro economics
Define macro economics
Max consumes two goods x and y, and ratio of marginal utility of x and y...
Max consumes two goods x and y, and ratio of marginal utility of x and y is always 2. The price of x is $2, and the price of y is $3. Income is $10. How much x does Max demand? How much y does Max demand?
P{X=k}=c|k|for k =-2,-1,1,2 and Y=max(0,X) where max means maximum. Thus, max(0,-3)=0, and max(0,3)=3. Commute the following....
P{X=k}=c|k|for k =-2,-1,1,2 and Y=max(0,X) where max means maximum. Thus, max(0,-3)=0, and max(0,3)=3. Commute the following. a) E[X] b) E[max(0,X)] c) P{Y=0}
Use the following returns for X and Y. Returns Year X Y 1 21.5 % 25.5...
Use the following returns for X and Y. Returns Year X Y 1 21.5 % 25.5 % 2 – 16.5 –3.5 3 9.5 27.5 4 19.0 –14.0 5 4.5 31.5 Calculate the average returns for X and Y. Average returns X % Y %    Calculate the variances for X and Y.    Variances X Y    Calculate the standard deviations for X and Y.    Standard deviations X % Y %
Find the absolute max and min for f(x,y) = (x-3)^2+y^2 on D={(x,y):0 ≤ x ≤ 4...
Find the absolute max and min for f(x,y) = (x-3)^2+y^2 on D={(x,y):0 ≤ x ≤ 4 , x^2 ≤ y ≤ 4x}.
Suppose that X and Y are indicators of A and B respectively. Show that 1−X,max(X,Y),XY are...
Suppose that X and Y are indicators of A and B respectively. Show that 1−X,max(X,Y),XY are all indicators and identify the corresponding events in terms of A and B.
Find the absolute min and max values of the function f(x, y) =x + y− x^2y...
Find the absolute min and max values of the function f(x, y) =x + y− x^2y on the closed triangular region with vertices (0,0), (3,0), and (0,3).
Find the maximum value of f(x,y)=(x^2)(y^7) for x,y≥0on the unit circle. f(max)=?
Find the maximum value of f(x,y)=(x^2)(y^7) for x,y≥0on the unit circle. f(max)=?
Use the max function to calculate max3(x, y, z) if x = 2, y = 6,...
Use the max function to calculate max3(x, y, z) if x = 2, y = 6, z = 5. Show your work!
Use the following returns for X and Y. Returns Year X Y 1 21.5 % 25.5...
Use the following returns for X and Y. Returns Year X Y 1 21.5 % 25.5 % 2 – 16.5 –3.5 3 9.5 27.5 4 19.0 –14.0 5 4.5 31.5 Calculate the average returns for X and Y. (Do not round intermediate calculations and enter your answers as a percent rounded to 2 decimal places, e.g., 32.16.) Average returns X % Y %    Calculate the variances for X and Y. (Do not round intermediate calculations and round your answers...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT