226k views
3 votes
Write a program that defines anduses macro MINIMUM2to determine the smallest of two numeric values. Input the valuesfrom the keyboard.

1 Answer

5 votes

Answer:

#include<iostream>

#define MINIMUM2(s1,s2) ((s1<s2?s1:s2))

using namespace std;

int main(){

//initialization

int s1,s2;

//display the message

cout<<"Enter the number 1: "<<endl;

cin>>s1; //read the input

cout<<"Enter the number 2: "<<endl;

cin>>s2; //read the input

//use micros

int min_Value = MINIMUM2(s1,s2);

//display

cout<<"The minimum value is: "<<min_Value<<endl;

return 0;

}

Step-by-step explanation:

Micros is the constants of symbols, values, etc.

it is used with the preprocessor directives represented by '#'. it means, the program process the information first before compiling the code.

syntax:

#define macro_name replacement_information

it actually, replace the information written in the macros into the code where we used the macros before the compilation.

In the above code,

we define the macros

#define MINIMUM2(s1,s2) ((s1<s2?s1:s2))

and create the main function and declare the variable.

after that, print the message by using the instruction cout and store the value enter by the user into the variable by using the instruction cin.

then, we use the macros the process copy the information ((s1<s2?s1:s2))

and replace where we call macros in the code.

so, actually before compilation

int min_Value = MINIMUM2(s1,s2);

the above statement becomes

int min_Value = ((s1<s2?s1:s2));

the above is a ternary operator, if s1 < s2 gives true then s1 will be the output otherwise s2 will be output.

and finally, we display the output on the screen.

User Black Swan
by
5.7k points