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 array is used in c?

0 Answers  


How can I delete a file?

0 Answers  


How can I handle floating-point exceptions gracefully?

0 Answers  


in programming languages a statement or part of a statement that specifies several different execution sequences a) constructs b) distructs c) executes d) none

0 Answers  


What is a memory leak in structures? How can we rectify that?

2 Answers  






find the sum of two matrices and WAP for it.

0 Answers   Huawei,


what is data structure

5 Answers   Maveric, TCS,


Write a program which calculate sum of several number and input it into an array. Then, the sum of all the number in the array is calculated.

2 Answers  


any restrictions have on the number of 'return' statements that may be present in a function. a) no restriction b) only 2 return statements c) only 1 return statements d) none of the above

0 Answers  


What is spaghetti programming?

0 Answers  


main() { printf("\n %d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); }

6 Answers  


Write a program of advanced Fibonacci series.

0 Answers   Aspiring Minds,


Categories