Advertisement
cd62131

Leap Year

Feb 16th, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. bool isLeapYear(int year) {
  4.   if (year < 1582) return false;
  5.   return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
  6. }
  7. int main(void) {
  8.   int i, years[] = {2000, 2001, 2002, 2003, 2004, 2005, 2100, 2200, 2300, 2400};
  9.   for (i = 0; i < (int) sizeof(years) / sizeof(int); i++) {
  10.     printf("%d is %s.\n", years[i],
  11.       (isLeapYear(years[i]) ? "leap year" : "not leap year"));
  12.   }
  13.   return 0;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement