LoginSignup
0
0

More than 3 years have passed since last update.

13日の金曜日(3桁) (paizaランク C 相当)

Posted at

問題文
YouTubeのYouTubeの解説動画を視て書いたコード

static void Main(string[] args)
        {
            int all = 0;
            int friday = 0;
            Random random = new Random(123456);
            for (int i = 0; i < 1000000; i++)
            {
                int year = random.Next(DateTime.MinValue.Year,DateTime.MaxValue.Year + 1); //無作為に選ぶ
                int month = random.Next(1, 13); //無作為に選ぶ
                //year年month月13日が金曜日ですか?
                DateTime date = new DateTime(year, month, 13);
                if(date.DayOfWeek.Equals(DayOfWeek.Friday) )
                {
                    friday++;
                }
                all++;
            }
            double result = (int)(((double)friday / all) * 1000) / 1000.0;
            Console.WriteLine(result);

        }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0