1234567891011121314151617181920 |
- //16
- int years = 2003;
- int weeks = CalculateWeekends(years);
- Console.WriteLine($"Количество выходных дней в {years} году: {weeks}");
- static int CalculateWeekends(int year)
- {
- DateTime date1 = new DateTime(year, 1, 1);
- DateTime date2 = new DateTime(year, 12, 31);
- int c = 0;
- for (var date = date1; date <= date2; date = date.AddDays(1))
- {
- if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
- {
- c++;
- }
- }
- return c;
- }
|