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

what is the need for main function in c?

5 Answers  


Do array subscripts always start with zero?

0 Answers  


What is the difference between text files and binary files?

0 Answers  


Write a C program linear.c that creates a sequence of processes with a given length. By sequence it is meant that each created process has exactly one child. Let's look at some example outputs for the program. Here the entire process sequence consists of process 18181: Sara@dell:~/OSSS$ ./linear 1 Creating process sequence of length 1. 18181 begins the sequence. An example for a sequence of length three: Sara@dell:~/OSSS$ ./linear 3 Creating process sequence of length 3. 18233 begins the sequence. 18234 is child of 18233 18235 is child of 18234 ........ this is coad .... BUt i could not compleate it .....:( #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int N; pid_t pid; int cont; if (argc != 2) { printf("Wrong number of command-line parameters!\n"); return 1; } N = atoi(argv[1]); printf("Creating process sequence of length %d.\n",N); printf("%d begins the sequence.\n",getpid()); /* What I have to do next ?????? */ }

0 Answers  


what are the uses of structure?

7 Answers   HCL,






Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it?

3 Answers  


What is a program flowchart and how does it help in writing a program?

0 Answers  


How to print India by nested loop? I IN IND INDI INDIA

4 Answers   NIIT, Wipro,


in which language c language is written?

2 Answers  


How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?

2 Answers   Aricent, Manipal University,


Determine if a number is a power of 2 at O(1).

2 Answers  


Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.

0 Answers   TCS,


Categories