Re: 28 or 29 days?

new topic     » goto parent     » topic index » view thread      » older message » newer message

> 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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu