It it now a leap year?
Rick Stevens
rstevens at internap.com
Wed Aug 8 18:11:19 UTC 2007
On Wed, 2007-08-08 at 12:31 -0400, Mike - EMAIL IGNORED wrote:
> Is there a system call or variable that will
> tell me if it is now a leap year, or should I
> do the arithmetic?
I don't know of one. The calculation is fairly simple. If the year is
evenly divisible by 100 (a "century year"), it must also be evenly
divisible by 400 to be a leap year. For example, 1900 was a not a leap
year, while 2000 was. The next century year that will be a leap year is
2400 (if we're still using the Gregorian calendar in the 25th century).
For non-century years, if it's evenly divisible by 4, it's a leap year.
Essentially, in C:
if (year % 100 == 0) {
if (year % 400 == 0)
printf("%d is a leap year\n", year);
else
printf("%d is NOT a leap year\n", year);
} else if (year % 4 == 0) {
printf("%d is a leap year\n", year);
} else {
printf("%d is NOT a leap year\n", year);
}
Sure seems as though it could be stuffed into the C library. It's
pretty trivial.
----------------------------------------------------------------------
- Rick Stevens, Principal Engineer rstevens at internap.com -
- CDN Systems, Internap, Inc. http://www.internap.com -
- -
- When in doubt, mumble. -
----------------------------------------------------------------------
More information about the fedora-list
mailing list