task14.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //14
  2. int years1 = 10;
  3. int count1 = 0;
  4. int count2 = 0;
  5. for (int year = 1; year <= years1; year++)
  6. {
  7. for (int month = 1; month <= 12; month++)
  8. {
  9. DateTime date1 = new DateTime(year, month, 13);
  10. if (date1.DayOfWeek == DayOfWeek.Friday)
  11. {
  12. count1++;
  13. }
  14. count2++;
  15. }
  16. }
  17. Console.WriteLine("Вероятности выпадения 13 числа каждого месяца на:");
  18. Console.WriteLine("Понедельник: " + (double)CountOfThirteenths(DayOfWeek.Monday) / count2);
  19. Console.WriteLine("Вторник: " + (double)CountOfThirteenths(DayOfWeek.Tuesday) / count2);
  20. Console.WriteLine("Среда: " + (double)CountOfThirteenths(DayOfWeek.Wednesday) / count2);
  21. Console.WriteLine("Четверг: " + (double)CountOfThirteenths(DayOfWeek.Thursday) / count2);
  22. Console.WriteLine("Пятницу: " + (double)count1 / count2);
  23. Console.WriteLine("Субботу: " + (double)CountOfThirteenths(DayOfWeek.Saturday) / count2);
  24. Console.WriteLine("Воскресенье: " + (double)CountOfThirteenths(DayOfWeek.Sunday) / count2);
  25. static int CountOfThirteenths(DayOfWeek day)
  26. {
  27. int count3 = 0;
  28. for (int year = 1; year <= 10; year++)
  29. {
  30. for (int month = 1; month <= 12; month++)
  31. {
  32. DateTime date1 = new DateTime(year, month, 13);
  33. if (date1.DayOfWeek == day)
  34. {
  35. count3++;
  36. }
  37. }
  38. }
  39. return count3;
  40. }