niepok

dzień tygodnia i piątek 13

Jan 25th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.11 KB | None | 0 0
  1. program piatek_13;
  2.  
  3. uses
  4.   crt;
  5.  
  6. function dzien_tygodnia(dzien, miesiac, rok : integer) : integer; //zmieniony algorytm Horzyka
  7. var
  8.   n, t : integer;
  9. begin
  10.   if (dzien > 0) and (dzien < 32) and (miesiac > 0) and (miesiac < 13)
  11.      and (rok > 1900) and (rok < 2100) then
  12.      begin
  13.        n := 6 + dzien + rok - 1990 + ((rok - 1990) div 4);
  14.        case miesiac of
  15.          4,7 : ;
  16.          1,10 : n:=n+1;
  17.          5 : n:=n+2;
  18.          8 : n:=n+3;
  19.          2,3,11 : n:=n+4;
  20.          6 : n:=n+5;
  21.          9,12 : n:=n+6
  22.        end;
  23.        if ((rok mod 4) = 0) and (miesiac<3) then n:=n-1;
  24.        t := n mod 7;
  25.        dzien_tygodnia := t
  26.      end
  27.   else dzien_tygodnia := 0
  28. end;
  29.  
  30. var
  31.   i, j, year, month, day, tmp : integer;
  32.  
  33. begin
  34.   writeln('Podaj dzien');
  35.   readln(day);
  36.   writeln('Podaj miesiac');
  37.   readln(month);
  38.   writeln('Podaj rok');
  39.   readln(year);
  40.   writeln(dzien_tygodnia(day, month, year));
  41.  
  42.   day:=13;
  43.   for i:=2010 to 2015 do
  44.     for j:=1 to 12 do
  45.     begin
  46.       tmp:=dzien_tygodnia(day, j, i);
  47.       if tmp = 5 then
  48.         writeln(day, ' ', j, ' ', i)
  49.     end;
  50.  
  51.   readln;
  52. end.
Advertisement
Add Comment
Please, Sign In to add comment