C++ Program to check whether a year is a leap year or not by using an user define functions. Leap year program

Explanation:

  1. Pass-by-Value (isLeapYearByValue):
    • Function Definition: bool isLeapYearByValue(int year)
    • This function takes the year as a parameter by value and checks whether it is a leap year.
    • It uses nested conditions:
      • If the year is divisible by 4, it proceeds to check divisibility by 100.
      • If divisible by 100, it further checks divisibility by 400.
      • Returns true if all conditions for a leap year are met; otherwise, it returns false.
  2. Pass-by-Reference (isLeapYearByReference):
    • Function Definition: void isLeapYearByReference(int year, bool &isLeapYear)
    • This function takes the year as a parameter by value but uses a reference parameter isLeapYear to store the result.
    • It performs the same checks as isLeapYearByValue but updates the isLeapYear reference variable with the result.
  3. Main Function (main):
    • The program prompts the user to input a year.
    • It calculates and displays whether the year is a leap year using both methods.

Example Outputs:

Example 1:

Input:

  • Year: 2024

Output:

Example 2:

Input:

  • Year: 1900

Output:

Example 3:

Input:

  • Year: 2000

Output: