Find greatest of two numbers using macro
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Why array is used in c?
How can I delete a file?
How can I handle floating-point exceptions gracefully?
in programming languages a statement or part of a statement that specifies several different execution sequences a) constructs b) distructs c) executes d) none
What is a memory leak in structures? How can we rectify that?
find the sum of two matrices and WAP for it.
what is data structure
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.
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
What is spaghetti programming?
main() { printf("\n %d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); }
Write a program of advanced Fibonacci series.