Advertisement
silvermistshadow

LeapYear.c Update (bool)

Nov 1st, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1.           // Silvermistshadow
  2.     // Program to tell if a year was/is/will be a leap year.
  3.     //Tests: Year   is leap year?
  4.     //      4000    yes
  5.     //      4004    yes
  6.     //      1999    no
  7.     //      1900    no
  8.     //      2000    yes
  9.     //      1904    yes
  10.    
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <stdbool.h>
  14.  
  15. #define START_OF_GREG_CALENDAR 1582
  16.  
  17. bool isLeapYear (int year) {
  18.     bool LeapYear = false;
  19.    
  20.  
  21. // notice this only works if the year is >= 1582
  22.    // because of the gregorian calendar stuff
  23.    if (year<START_OF_GREG_CALENDAR) {
  24.    LeapYear = false;
  25.    }
  26.    else {
  27.             if ((year % 400) == 0) {
  28.                LeapYear = true;
  29.            } else {
  30.                 if ((year % 100) > 0) {
  31.                      if ((year % 4) == 0) {
  32.                           LeapYear = true;
  33.                     } else {
  34.                     LeapYear = false;
  35.                     }
  36.             } else {
  37.                        LeapYear = false;
  38.         }
  39.     }
  40.         }
  41.  
  42.    return LeapYear;
  43. }
  44.  
  45. int main (int argc, const char * argv[]) {
  46.  
  47.    int year;
  48.  
  49.    printf ("please enter the year you are interested in\n");
  50.    scanf("%d", &year);
  51.    if (isLeapYear(year)) {
  52.    printf("%d is a leap year!\n", year);
  53.        } else {
  54.        printf ("%d is not a leap year!\n", year);
  55.        }
  56.    
  57.          
  58.     return EXIT_SUCCESS;
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement