BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C++ Program to Check Leap Year using function

Last Updated: September 7, 2017 by Chaitanya Singh | Filed Under: C++ Programs

This program takes the value of year(entered by user) and checks whether the input year is Leap year or not. The steps to check leap year are as follows:
To determine whether a year is a leap year, here are the steps: Source of these steps.
Step 1: If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
Step 2: If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
Step 3: If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
Step 4: The year is a leap year (it has 366 days).
Step 5: The year is not a leap year (it has 365 days).
Lets write these steps in a C++ program.

Example: Program to check whether the input year is leap year or not

To understand this program, you should have the knowledge of C++ functions and if-else.

#include <iostream>
using namespace std;

bool leapYear(int y);

int main(){
   int y;
   cout<<"Enter year: ";
   cin>>y;
   //Calling function
   bool flag = leapYear(y);
   if(flag == true)  
      cout<<y<<" is a leap Year"; 
   else 
      cout<<y<<" is not a leap Year";
   return 0;
}
bool leapYear(int y){
   bool isLeapYear = false;
   if (y % 4 == 0) {
      if (y % 100 == 0) {
         if (y % 400 == 0) {
            isLeapYear = true;
         }
      } 
      else isLeapYear = true;
   }
   return isLeapYear;
}

Output:

Enter year: 2016
2016 is a leap Year

Top Related Articles:

  1. C++ Program to Check whether an input number is Prime or not
  2. C++ Program to display prime numbers from 1 to 100 and 1 to n
  3. C++ Program to check Armstrong Number
  4. C++ Program to Find the sum of n natural numbers using Recursion
  5. C++ Program to Check Prime Number using Function

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap