1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- //14
- int years1 = 10;
- int count1 = 0;
- int count2 = 0;
-
- for (int year = 1; year <= years1; year++)
- {
- for (int month = 1; month <= 12; month++)
- {
- DateTime date1 = new DateTime(year, month, 13);
- if (date1.DayOfWeek == DayOfWeek.Friday)
- {
- count1++;
- }
- count2++;
- }
- }
- Console.WriteLine("Вероятности выпадения 13 числа каждого месяца на:");
- Console.WriteLine("Понедельник: " + (double)CountOfThirteenths(DayOfWeek.Monday) / count2);
- Console.WriteLine("Вторник: " + (double)CountOfThirteenths(DayOfWeek.Tuesday) / count2);
- Console.WriteLine("Среда: " + (double)CountOfThirteenths(DayOfWeek.Wednesday) / count2);
- Console.WriteLine("Четверг: " + (double)CountOfThirteenths(DayOfWeek.Thursday) / count2);
- Console.WriteLine("Пятницу: " + (double)count1 / count2);
- Console.WriteLine("Субботу: " + (double)CountOfThirteenths(DayOfWeek.Saturday) / count2);
- Console.WriteLine("Воскресенье: " + (double)CountOfThirteenths(DayOfWeek.Sunday) / count2);
- static int CountOfThirteenths(DayOfWeek day)
- {
- int count3 = 0;
- for (int year = 1; year <= 10; year++)
- {
- for (int month = 1; month <= 12; month++)
- {
- DateTime date1 = new DateTime(year, month, 13);
- if (date1.DayOfWeek == day)
- {
- count3++;
- }
- }
- }
- return count3;
- }
|