Thursday, March 26, 2015

Check if it is a leap year


Script

#include <iostream>
using namespace std;

main()
{
        int year, remainder, divby100, divby400;

        cout << "Enter an year: ";
        cin >> year;

        remainder = year % 4;
        divby100 = year % 100;
        divby400 = year % 400;

        cout << "\n";

        if ((remainder == 0) && (divby100 != 0) || (divby400 == 0))
        cout << year << " is a leap year \n\n";
        else
        cout << "\n" << year << " is not a leap year \n\n";

        return 0;
}


Execution


Enter an year: 2015

2015 is not a leap year



Enter an year: 2020

2020 is a leap year



Enter an year: 2100

2100 is not a leap year



Enter an year: 2200

2200 is not a leap year



Enter an year: 2300

2300 is not a leap year



Enter an year: 2400

2400 is a leap year







No comments:

Post a Comment