C++ Examples – C++ Program to Check Leap Year




cpp tutorials
cpp tutorials

In the Julian Calendar, Leap Year (LY) occurs every year divisible by 4. Normally February has 28 days but in a leap year February has 29 days.

In this lesson we will learn how to write a C++ program to check if the giver year is leap year or not.

#include <iostream>

using namespace std;

int main()
{
  int year;
  cout<<"Enter a year: "<< endl;
  cin>> year;
  if((year % 4) ==0)
  {
    cout<<" Leap Year ";
  }
  else
  {
    cout <<" Not a Leap Year" << endl;
  }
  return 0;
}

/*
Enter a year: 2016
Leap Year
*/

After you write a C++ program you compile it; that is, you run a program called compiler that checks whether the program follows the C++ syntax

  • if it finds errors, it lists them
  • If there are no errors, it translates the C++ program into a program in machine language which you can execute

 

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





1 Comment

  1. 2000 was a leap year. Since 1752, in this country, years exactly divisible by 100 are only leap years when they are also exactly divisible by 400. So 1800 and 1900 were not leap years, neither will 2100 or 2200 be leap years.

Leave a Reply

Your email address will not be published.


*