Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Silvermistshadow
- // Program to tell if a year was/is/will be a leap year.
- //Tests: Year is leap year?
- // 4000 yes
- // 4004 yes
- // 1999 no
- // 1900 no
- // 2000 yes
- // 1904 yes
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #define START_OF_GREG_CALENDAR 1582
- bool isLeapYear (int year) {
- bool LeapYear = false;
- // notice this only works if the year is >= 1582
- // because of the gregorian calendar stuff
- if (year<START_OF_GREG_CALENDAR) {
- LeapYear = false;
- }
- else {
- if ((year % 400) == 0) {
- LeapYear = true;
- } else {
- if ((year % 100) > 0) {
- if ((year % 4) == 0) {
- LeapYear = true;
- } else {
- LeapYear = false;
- }
- } else {
- LeapYear = false;
- }
- }
- }
- return LeapYear;
- }
- int main (int argc, const char * argv[]) {
- int year;
- printf ("please enter the year you are interested in\n");
- scanf("%d", &year);
- if (isLeapYear(year)) {
- printf("%d is a leap year!\n", year);
- } else {
- printf ("%d is not a leap year!\n", year);
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement