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 |
Hi Every one...........I have been selected for the SBI Clerk. But i m one month Pregnanat. So anyone please suggest me, is they take any objection on my joining .
4 Answers State Bank Of India SBI,
Write a code on reverse string and its complexity.
What is time null in c?
what do the 'c' and 'v' in argc and argv stand for?
What is the memory allocated by the following definition ? int (*x)[10];
i want to have a program to read a string and print the frequency of each character and it should work in turbo c
What is the difference between %d and %i?
How can I get Single byte from 'int' type variable? Can we alter single bit or multiple bits in int type variable? if so, How?
List some of the static data structures in C?
Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
How can I read in an object file and jump to locations in it?
What is pointer to pointer in c?