Description
Write a program to print the number of leap years in the given list of years.
Input:
First line of input is total number of years (n)
Next n lines will be the years.
Output:
Print the number of leap years found in the given list of years.
Answers
Answer:
Following is pseudo-code
if year is divisible by 400 then is_leap_year
else if year is divisible by 100 then not_leap_year
else if year is divisible by 4 then is_leap_year
else not_leap_year
C++CJavaPython3C#PHP
C++
// C++ program to check if a given
// year is leap year or not
#include <bits/stdc++.h>
using namespace std;
bool checkYear(int year)
{
// If a year is multiple of 400,
// then it is a leap year
if (year % 400 == 0)
return true;
// Else If a year is multiple of 100,
// then it is not a leap year
if (year % 100 == 0)
return false;
// Else If a year is multiple of 4,
// then it is a leap year
if (year % 4 == 0)
return true;
return false;
}
// Driver code
int main()
{
int year = 2000;
checkYear(year) ? cout << "Leap Year":
cout << "Not a Leap Year";
return 0;
}
// This is code is contributed
// by rathbhupendra
C
Java
Python3
C#
PHP