Write a C program to search out most and minimal of two numbers utilizing macro. discover most or minimal between two numbers utilizing macro in C program. Logic to search out most and minimal utilizing macro in C.
In final publish we discovered including circumstances to our macro. We discovered to test even or odd quantity utilizing macro.
On this publish we are going to proceed the train additional. I’ll clarify how simply you’ll be able to rework our most or minimal test operate to macro.
Required information
Primary C programming, Macros, Conditional operator
There are a number of methods to test most or minimal between two numbers. In case you missed I’ve listed down the hyperlinks beneath.
discover most or minimal utilizing macro?
I assume that you’re already conscious with macro syntax, the best way to outline and use. Therefore, with out losing a lot time allow us to get began.
Lets outline two macro that accepts two arguments say MAX(x, y)
and MIN(x, y)
. It is going to return most or minimal quantity respectively. For this train we are going to use conditional (ternary) operator to search out most or minimal.
Instance:
#outline MAX(x, y) (x > y ? x : y)
#outline MIN(x, y) (x < y ? x : y)
Program to search out most or minimal utilizing macro
/**
* C program to test most/minimal utilizing macro
*/
#embody <stdio.h>
// Outline macro to test most and minimal
#outline MAX(x, y) (x > y ? x : y)
#outline MIN(x, y) (x < y ? x : y)
int major()
{
int num1, num2;
// Enter numbers from consumer
printf("Enter any two quantity to test max and min: ");
scanf("%dpercentd", &num1, &num2);
printf("MAX(%d, %d) = %dn", num1, num2, MAX(num1, num2));
printf("MIN(%d, %d) = %dn", num1, num2, MIN(num1, num2));
return 0;
}
discover most or minimal between three numbers utilizing ternary operator?
Enter any two quantity to test max and min: 10 20 MAX(10, 20) = 20 MIN(10, 20) = 10
Completely satisfied coding 😉