ADVERTISEMENT
ADVERTISEMENT

Home » Code Snippets » C/C++ Code Snippets

C program to define Macro to find minimum of two numbers

Here, we will learn how to define a Macro that will take arguments to find minimum of two numbers?

Here is the Macro

#define MIN(x,y) ((x<y)?x:y)

Here, MIN is the Macro name x and y are the arguments. When program will compile, actual arguments which will be passed into the MIN Macro.

The code segment ((x<y)?x:y) will be replaced as ((a<b)?a:b) (a and b are the actual arguments in the below written program) instead of Macro calling MIN(a,b).

Program

#include <stdio.h>

#define MIN(x,y) ((x<y)?x:y)

int main()
{
	int a,b,min;
	
	printf("Enter first number: ");
	scanf("%d",&a);
	printf("Enter second number: ");
	scanf("%d",&b);	
	
	min=MIN(a,b);
	printf("Minimum number is: %d\n",min);
	
	return 0;
}

Output

Enter first number: 100 
Enter second number: 200
Minimum number is: 100
ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.