Guest User

Tính thứ ngày tháng

a guest
Sep 16th, 2019
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {Chương trình tính thứ ngày tháng}
  2. program Hello;
  3. uses crt;
  4. const day = 1;
  5. const month = 2;
  6. const year = 3;
  7.  
  8. const monday = 0;
  9. const tuesday = 1;
  10. const wednesday=2 ;
  11. const thursday = 3;
  12. const friday =4 ;
  13. const saturday = 5;
  14. const sunday = 6;
  15.  
  16. type date = array[1..3] of Integer;
  17. type month_table = array[1..12] of Byte;
  18. var today : date;
  19. var input_date : date;
  20. var counter_date : date;
  21. var day_of_week : Integer;
  22. const days_of_months : month_table = (31, 28, 31, 30, 31, 30 , 31, 31, 30, 31, 30,31);
  23.  
  24.  
  25.  
  26.  
  27.  
  28. procedure date_to_string(_date : date);
  29. begin
  30.   Writeln(_date[day] ,'/' , _date[month] , '/' , _date[year]);
  31. end;
  32. function is_equal(date1 ,date2 : date) : boolean;
  33. var condition1, condition2, condition3 : boolean;
  34. begin
  35.      condition1   := date1[day]   = date2[day];
  36.      condition2   := date1[month] = date2[month];
  37.      condition3   := date1[year]  = date2[year];
  38.      is_equal     := condition1 and condition2 and condition3;
  39. end;
  40. function increase(date : date) : date ;
  41. begin
  42.   // leap year
  43.   if((date[year] mod 4 = 0) and (date[year] mod 100 <> 0)) then
  44.      days_of_months[2] := 29
  45.     else
  46.      days_of_months[2] := 28;
  47.  
  48.   date[day] := date[day] + 1;
  49.   if(date[day] > days_of_months[date[month]]) then begin
  50.     date[month] := date[month] + 1;
  51.     // first day of next month
  52.     date[day]   := 1;
  53.   end;
  54.   if(date[month] > 12) then begin
  55.     date[year] := date[year] + 1;
  56.     // first month of a year;
  57.     date[month]:= 1;
  58.   end;
  59.   increase := date;
  60. end;
  61. begin
  62.     Clrscr;
  63.     {16/9/2019}
  64.     today[day] := 17; today[month] := 9; today[year] :=2019; day_of_week := tuesday;
  65.     // Read Input
  66.     Writeln('Ban hay nhap ngay = '); read(input_date[day]);
  67.     Writeln('Ban hay nhap thang ='); Read(input_date[month]);
  68.     Writeln('Ban hay nhap nam =');   Read(input_date[year]);
  69.     counter_date := today;
  70.     // while counter <= input;
  71.     Readln;
  72.     repeat
  73.         counter_date := increase(counter_date);
  74.         date_to_string(counter_date);
  75.         day_of_week := day_of_week + 1;
  76.     until is_equal(counter_date , input_date);
  77.     day_of_week := day_of_week mod 7;
  78.     case day_of_week of
  79.       monday   :  WriteLn('Thu 2');
  80.       tuesday  :  WriteLn('Thu 3');
  81.       wednesday:  WriteLn('Thu 4');
  82.       thursday :  WriteLn('Thu 5');
  83.       friday   :  WriteLn('Thu 6');
  84.       saturday :  WriteLn('Thu 7');
  85.       sunday   :  WriteLn('Chu nhat');
  86.     end;
  87.     Readln;
  88. end.
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×