1. 28 or 29 days?
- Posted by Architek <architek at GEOCITIES.COM> Apr 25, 1997
- 1002 views
Hi all, I need URGENTLY an algorithm to see is a given year is a leap year. Can any of you help me? I bet that in some old book it appears ;) Thanks -- ************************************ This message sent by Daniel Berstein ************************************ email: architek at geocities.com homepages: http://www.geocities.com/SiliconValley/Heights/9316 http://www.cybercity.hko.net/silicon_valley/architek
2. Re: 28 or 29 days?
- Posted by Michael Bolin <michaeltom at GEOCITIES.COM> Apr 25, 1997
- 1005 views
- Last edited Apr 26, 1997
> Hi all, > > I need URGENTLY an algorithm to see is a given year is a leap year. > Can any of you help me? I bet that in some old book it appears ;) Here's a short routine that'll do that: function leap_year (integer year) -- Returns true if year is a leap year, otherwise false. if year<1582 then if remainder(year,4)=0 then return 1 else return 0 end if else if remainder(year,400)=0 then return 1 elsif remainder(year,100)=0 then return 0 elsif remainder(year,4)=0 then return 1 else return 0 end if end if end function Regards, Michael Bolin
3. Re: 28 or 29 days?
- Posted by Matthew Green <pogowolf at IASTATE.EDU> Apr 26, 1997
- 1037 views
> Hi all, > > I need URGENTLY an algorithm to see is a given year is a leap year. > Can any of you help me? I bet that in some old book it appears ;) > > This message sent by Daniel Berstein I hope that you do not mind that it's in C++ code.. but, it will give you the Idea!!! --- PogoWolf, pogowolf at iastate.edu HTTP://www.public.iastate.edu/~pogowolf Off the 10Base-T, through the router, down the T3, over the Fiber line, off the bridge, past the firewall.... Nothing but Net. // Title: Leap Year.C // Author: Matthew Green // UserName: PogoWolf // Section: L // TA: Haverdink // // Started: 2/25/97 // Finished: 2/26/97 // reversion: 2/27/96 #include <fstream.h> void main(){ int TestYear; // Set up the years.in file for input... ifstream infile; infile.open ("years.in"); // Set up the years.out for output... ofstream outfile; outfile.open ("years.out"); // Read the years from file to test... infile >> TestYear; // While loop will run as long as their isa a Year to be read from infile... while (infile){ //is TestYear a leap year? if ((TestYear%4 == 0 && TestYear%100 != 0) || (TestYear%400 == 0 && TestYear%1 00 == 0 )) outfile << TestYear << " IS a leap year" << endl; else outfile << TestYear << " is NOT a leap year" << endl; // Get next year... infile >> TestYear; }// end while } // End Main