Cpp: Inline Functions 5

Example:2
Program to print maximum of two numbers.

#include <iostream>
 
using namespace std;

inline int Max(int x, int y) 
{
   return (x > y)? x : y;
}

// Main function for the program
int main() 
{
   cout << "Max (20,10): " << Max(20,10) << endl;
   cout << "Max (0,200): " << Max(0,200) << endl;
   cout << "Max (100,1010): " << Max(100,1010) << endl;
   
   return 0;
}

Output:

Max (20,10): 20
Max (0,200): 200
Max (100,1010): 1010

Example:3
Program to print minimum of two numbers.

#include <iostream>
 
using namespace std;

inline int Min(int x, int y) 
{
   return (x < y)? x : y;
}

// Main function for the program
int main() 
{
   cout << "Min (20,10): " << Min(20,10) << endl;
   cout << "Min (0,200): " << Min(0,200) << endl;
   cout << "Min (100,1010): " << Min(100,1010) << endl;
   
   return 0;
}

Output:

Min (20,10): 10
Min (0,200): 0
Min (100,1010): 100