Exemplo n.º 1
0
Arquivo: Form1.cs Projeto: elh4mm/LINQ
        TimeData StartFactorial(int n)
        {
            var result = new TimeData();

            AppendText($"Calculating Factorial({n})");
            result.StartTime = DateTime.Now;
            double value = GetFactorial(n);

            result.EndTime = DateTime.Now;

            AppendText($"Factorial({n}) = {value}");
            result.total =
                (result.EndTime - result.StartTime).TotalMinutes;
            AppendText($"Calculation time = {result.total:F6} minutes\r\n");
            return(result);
        }
Exemplo n.º 2
0
Arquivo: Form1.cs Projeto: elh4mm/LINQ
        TimeData RollDie(int number)
        {
            var result = new TimeData();

            result.StartTime = DateTime.Now;

            AppendText($"Calculating RollDie(60000000)");

            Random random = new Random();
            int    c;
            int    i = 0;

            int[] intArr = { 0, 0, 0, 0, 0, 0, 0 };
            int   face   = 0;

            while (i < number)
            {
                c = random.Next(1, 7);

                intArr[c] = ++intArr[c];

                i++;
            }

            int max = 1;

            for (int j = 0; j < intArr.Length; j++)
            {
                if (intArr[j] > max)
                {
                    max  = intArr[j];
                    face = j;
                }
            }
            AppendText($"RollDie    The most fequent Face is \"{face}\" with number of {max} times");
            result.EndTime = DateTime.Now;
            result.total   =
                (result.EndTime - result.StartTime).TotalMinutes;
            AppendText($"Calculation time = {result.total:F6} minutes\r\n");
            return(result);
        }