Wednesday, 23 April 2014

12. Define two separate macros, MIN and MAX, to find and return, respectively, the minimum and maximum of two values. Write a sample program that uses these macros. Hint: Use the ternary operator.



#include<stdio.h>
#include<conio.h>

#define min(x,y)(x<y ? x:y)
#define max(x,y)(x>y ? x:y)

void main()
{
          int i,j;
          clrscr();
          printf("\n\n\t Enter two numbers to compare :-");
          printf("\n\n\tFirst Number -> ");
          scanf("%d", &i);
          printf("\n\tSecond Number -> ");
          scanf("%d", &j);
          printf("\n\n\tThe maximum number is %d", max(i,j));
          printf("\n\n\tThe minimum number is %d", min(i,j));
          getch();
}

No comments:

Post a Comment