Find greatest of two numbers using macro

Answers were Sorted based on User's Feedback



Find greatest of two numbers using macro..

Answer / banavathvishnu

#include<stdio.h>
#include<conio.h>

#define Greatest(X,Y) X>Y?X:Y

int main()
{
int x,y;
scanf("%d %d",&x,&y);
printf("%d",Greatest(x,y));
getch();
}

Is This Answer Correct ?    91 Yes 10 No

Find greatest of two numbers using macro..

Answer / senthil

#define Greatest(a,b) (a>b)?a:b

Is This Answer Correct ?    45 Yes 5 No

Find greatest of two numbers using macro..

Answer / subbu

While defining macro's for each parameter enclosing brackets
is preferred. For finding out greatest of two numbers better
way writing macro is as below.

#define Greatest(a,b) ((a)>(b))?(a):(b)


If this method not followed, the in the following example
results will be wrong.


#define Product(a,b) (a*b) /* Wrong method */

Bcz if call is done as below

Product(2+3, 4+5) then result will come as (2+3*4+5) = 19
instead of 45.

Is This Answer Correct ?    20 Yes 4 No

Find greatest of two numbers using macro..

Answer / sourav ray

#include<stdio.h>
#include<conio.h>
#define big(a,b) (a>b)?a:b
void main()
{int x,y;
clrscr();
printf("enter the valus of x and y:\n");
scanf("%d%d",&x,&y);
printf("the biggest value is",big(x,y)");
getch();
}

Is This Answer Correct ?    16 Yes 6 No

Post New Answer

More C Interview Questions

Why can't we initialise member variable of a strucutre

1 Answers  


how to print the character with maximum occurence and print that number of occurence too in a string given ?

0 Answers   Microsoft,


What is null pointer constant?

0 Answers  


What is page thrashing?

0 Answers  


Table of Sudoku n*n

0 Answers  






how to find sum of digits in C?

21 Answers   CTS, Infosys,


What is the size of enum in c?

0 Answers  


Compare and contrast compilers from interpreters.

0 Answers  


a<<1 is equivalent to a) multiplying by 2 b) dividing by 2 c) adding 2 d)none of the above

2 Answers   HCL, NBN,


explain what are actual arguments?

0 Answers  


main() { enum{red,green,blue=6,white}; pf("%d%d%d%d", red,green,blue,white); return 0; } a)0 1 6 2 b)0 1 6 7 c)Compilation error d)None of the above

6 Answers  


What should be keep precautions while using the recursion method?

1 Answers  


Categories