C++ Program to find the maximum between two numbers by using the user define functions. Maximum Number Program

Explanation:

  1. Pass-by-Value (findMaxByValue):
    • Function Definition: int findMaxByValue(int num1, int num2)
    • This function takes two integers num1 and num2 as input parameters by value (i.e., copies of the original values).
    • It compares the two numbers and returns the larger one.
  2. Pass-by-Reference (findMaxByReference):
    • Function Definition: void findMaxByReference(int num1, int num2, int &maxNum)
    • This function takes two integers num1 and num2, and a reference to an integer maxNum.
    • It compares num1 and num2, and assigns the larger value directly to the maxNum reference.
    • This allows the original variable in the calling function to be updated.
  3. Main Function (main):
    • The program prompts the user to enter two numbers.
    • It then calculates the maximum of the two numbers using both the pass-by-value and pass-by-reference methods.
    • Finally, it prints the maximum number found by each method.

Example Outputs:

Example 1:

Input:

  • First Number: 15
  • Second Number: 22

Output:

Example 2:

Input:

  • First Number: 8
  • Second Number: 3

Output:

Example 3:

Input:

  • First Number: 5
  • Second Number: 5

Output: