algorytm.org

Implementacja w Delphi/Pascal



Baza Wiedzy
wersja offline serwisu przeznaczona na urządzenia z systemem Android
Darowizny
darowiznaWspomóż rozwój serwisu
Nagłówki RSS
Artykuły
Implementacje
Komentarze
Forum
Bookmarki






Sonda
Implementacji w jakim języku programowania poszukujesz?

Wyznaczanie daty Wielkanocy - algortym Gaussa - Implementacja w Delphi/Pascal
Ocena użytkownikóww: *****  / 4
SłabyŚwietny
Nadesłany przez Tomasz Lubiński, 19 lutego 2008 01:00
Kod przedstawiony poniżej przedstawia główną część rozwiązania problemu.
Pobierz pełne rozwiązanie.

Jeżeli nie odpowiada Ci sposób formatowania kodu przez autora skorzystaj z pretty printer'a i dostosuj go automatycznie do siebie.

Data wielkanocy algorytm Gaussa - Delphi/dw.dpr:
// Obliczanie daty wielkanocy - algorytm Gaussa
// www.algorytm.org
// (c) 2008 by Tomasz Lubinski

program dw;
{$APPTYPE CONSOLE}
uses
  SysUtils;

// Pobierz wartosc A z tabeli lat
function getA(rok: Integer): Integer;
begin
   if (rok <= 1582) then
      result := 15
   else if (rok <= 1699) then
      result := 22
   else if (rok <= 1899) then
      result := 23
   else if (rok <= 2199) then
      result := 24
   else if (rok <= 2299) then
      result := 25
   else if (rok <= 2399) then
      result := 26
   else if (rok <= 2499) then
      result := 25
   else
      result := 0; // poza zakresem
end;

// Pobierz wartosc B z tabeli lat
function getB(rok: Integer): Integer;
begin
   if (rok <= 1582) then
      result := 6
   else if (rok <= 1699) then
      result := 2
   else if (rok <= 1799) then
      result := 3
   else if (rok <= 1899) then
      result := 4
   else if (rok <= 2099) then
      result := 5
   else if (rok <= 2199) then
      result := 6
   else if (rok <= 2299) then
      result := 0
   else if (rok <= 2499) then
      result := 1
   else
      result := 0; // poza zakresem
end;

// oblicz ile dni po 22 marca przypada wielkanoc
function wielkanoc(rok: Integer): Integer;
var
   a, b, c, d, e: Integer;
begin

   a := rok mod 19;
   b := rok mod 4;
   c := rok mod 7;
   d := (a*19 + getA(rok)) mod 30;
   e := (2*b + 4*c + 6*d + getB(rok)) mod 7;

   if (((d = 29) and (e = 6)) or
       ((d = 28) and (e = 6))) then
   begin
      d := d-7;
   end;

   result := d+e;
end;

var
   rok : Integer;
   data : Integer;

begin

   writeln('Podaj rok (33-2499)');
   readln(rok);
   
   if ((rok < 33) or (rok > 2499)) then
   begin
      writeln('Podany rok nie jest w zakresie 33-2499.');
      exit;
   end;

   data := 22 + wielkanoc(rok);
   if (data > 31) then
      writeln('Wielkanoc przypada ' + IntToStr(data mod 31)+ ' kwietnia')
   else
      writeln('Wielkanoc przypada ' + IntToStr(data)+ ' marca');

end.
Dodaj komentarz