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

int main() { int i=-1,j=-1;k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d%d%d%d%d",i,j,k,l,m); }

3 Answers   HCL,


What does the message "warning: macro replacement within a string literal" mean?

1 Answers  


what is the function of pragma directive in c?

0 Answers  


What is a pointer value and address in c?

0 Answers  


Why c language is called c?

0 Answers  






What is the difference between the = symbol and == symbol?

0 Answers  


What is the output of the following progarm? #include<stdio.h> main( ) { int x,y=10; x=4; y=fact(x); printf(ā€œ%d\nā€,y); } unsigned int fact(int x) { return(x*fact(x-1)); } A. 24 B. 10 C. 4 D. none

2 Answers  


A stack can be implemented only using array?if not what is used?

3 Answers   InterGlobal,


What is the purpose of sprintf?

0 Answers  


Why is c called a mid-level programming language?

0 Answers  


biggest of two no's with out using if condition statement

8 Answers  


Write a program that his output 1 12 123

0 Answers  


Categories