Quick links: C-Tricks HR Interview Que. Code Snippets C Programs C++ Programs Java Programs PHP Examples

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

C program to define Macro to find maximum of two numbers

By: IncludeHelp On 27 DEC 2016

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

Here is the Macro

#define MAX(x,y) ((x>y)?x:y)

Here, MAX is the Macro name x and y are the arguments. When program will compile, actual arguments which will be passed into the MAX 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 MAX(a,b).


Sponsored Links



Program

#include <stdio.h>

#define MAX(x,y) ((x>y)?x:y)

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

Output

Enter first number: 100 
Enter second number: 200
Maximum number is: 200
Solved programs


Sponsored Links


Most viewed pages


Featured posts
C Tips and Tricks

Keywords (like Linux, Java, Oracle etc) used in this website are the trademarks of their respective owners/company. This website is not affiliated to any company. The tutorials are designed by includehelp Team with the help of well known books and other online resources. These Tutorials are free for all, for learning purposes only. Enjoy learning:)
Copyright © 2015 - 2016. All Rights Reserved.