Forum > General

problem with leap year to count.

<< < (2/2)

engkin:

--- Quote from: marcov on November 22, 2014, 05:58:19 pm ---Dateutils has


--- Code: ---Function IsInLeapYear(const AValue: TDateTime): Boolean;

--- End code ---

--- End quote ---
Can't be used in school assignment.

Bart:

--- Quote from: engkin on November 22, 2014, 07:45:12 pm ---
--- Quote from: marcov on November 22, 2014, 05:58:19 pm ---Dateutils has


--- Code: ---Function IsInLeapYear(const AValue: TDateTime): Boolean;

--- End code ---

--- End quote ---
Can't be used in school assignment.

--- End quote ---

But function can be copied to impress teacher.

Bart

BrunoK:
Or a different one.

--- Code: ---  function Fun_IsLeapYear(aYear: integer): boolean;
begin
  Result := (aYear and 3) = 0;   // Test simple case
  if Result then begin
    aYear:=aYear shr 2;          // Reduce (Divide by 4)
    Result:=(aYear mod 25)<>0;   // Eliminate those that cannot
    if not Result then           // ..be divided by 100, they are always leaps
      Result:=(aYear and 3)=0;   // Those that can be divided by 4(00) are leaps
  end;
end;

--- End code ---

Windsurfer:
Engkin,  thanks for the correction.  Thankfully I did know it correctly in 1999!
The lesson for me is to check before posting.

engkin:

--- Quote from: Bart on November 22, 2014, 11:13:09 pm ---But function can be copied to impress teacher.

--- End quote ---
@Bart, your reply cheered me up, thanks. Impressing teachers would result in harder assignments!


--- Quote from: Windsurfer on November 23, 2014, 05:42:22 pm ---Thankfully I did know it correctly in 1999!

--- End quote ---
@Windsurfer, retaining anything related to this for so long is nearly impossible for me.

Navigation

[0] Message Index

[*] Previous page

Go to full version