task16.cs 532 B

1234567891011121314151617181920
  1. //16
  2. int years = 2003;
  3. int weeks = CalculateWeekends(years);
  4. Console.WriteLine($"Количество выходных дней в {years} году: {weeks}");
  5. static int CalculateWeekends(int year)
  6. {
  7. DateTime date1 = new DateTime(year, 1, 1);
  8. DateTime date2 = new DateTime(year, 12, 31);
  9. int c = 0;
  10. for (var date = date1; date <= date2; date = date.AddDays(1))
  11. {
  12. if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
  13. {
  14. c++;
  15. }
  16. }
  17. return c;
  18. }