Wednesday, February 20, 2019

Leap Years

Write a program that tells if a year is or is not a leap year.

A leap year has 366 days. After the Gregorian reform, the leap years are those multiple of four that do not end with two zeros, and also the years ending with two zeros such that, after removing these two zeros, are divisible by four. Thus, 1800 and 1900, although being multiples of four, were not leap years; by contrast, 2000 was a leap year.

Input: Input consists of a natural number between 1800 and 9999.

Output: If the year is a leap year, print “YES”; otherwise print “NO”.

#include <iostream>
using namespace std;

int main () {
    int a;
    cin >> a;
    if (a%100 == 0) {
        int n;
        n=a/100;
        if(n%4== 0) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if (a%4 ==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

No comments:

Post a Comment

Modelo OSI

Open System Interconnection , Interconexión de Sistemas Abiertos, es un modelo para estudiar las categorías en que se pueden dividir los pr...