Created
April 17, 2016 03:14
-
-
Save bzdgn/4809aa07a74180c33871023b2a70f72f to your computer and use it in GitHub Desktop.
Leap Year Demo in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| typedef enum { FALSE, TRUE } boolean; | |
| boolean isLeapYear(int); | |
| char* getLeapInfo(int); | |
| int main() | |
| { | |
| for(int i = 1980; i <= 2017; i++) | |
| printf("%d %s\n", i, getLeapInfo(i)); | |
| return 0; | |
| } | |
| boolean isLeapYear(int year) | |
| { | |
| if( (year%4 == 0 && year%100)!= 0 || (year%400 == 0) ) | |
| return TRUE; | |
| return FALSE; | |
| } | |
| char* getLeapInfo(int year) | |
| { | |
| if( isLeapYear(year) == TRUE ) | |
| return "is a LEAP year"; | |
| return "not a leap year"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output;
1980 is a LEAP year
1981 not a leap year
1982 not a leap year
1983 not a leap year
1984 is a LEAP year
1985 not a leap year
1986 not a leap year
1987 not a leap year
1988 is a LEAP year
1989 not a leap year
1990 not a leap year
1991 not a leap year
1992 is a LEAP year
1993 not a leap year
1994 not a leap year
1995 not a leap year
1996 is a LEAP year
1997 not a leap year
1998 not a leap year
1999 not a leap year
2000 is a LEAP year
2001 not a leap year
2002 not a leap year
2003 not a leap year
2004 is a LEAP year
2005 not a leap year
2006 not a leap year
2007 not a leap year
2008 is a LEAP year
2009 not a leap year
2010 not a leap year
2011 not a leap year
2012 is a LEAP year
2013 not a leap year
2014 not a leap year
2015 not a leap year
2016 is a LEAP year
2017 not a leap year