Saturday, 6 December 2014

Define two separate macros,MIN & MAX, to find and return, respectively the minimum & maximum of two values. Write a sample program that usesthese macros.

#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

Please write your doubts