dimanche 10 octobre 2021

how to get the average of random numbers

I have a loop that repeats itself 100 times and every time it generates a random number

Random rnd = new Random();
        const double MAX = 42.0;
        const double MIN = 34.5;
        double ex4 = 0;
        for (int i = 0; i < 101; i++)
        {
            double num = rnd.NextDouble() * (MAX - MIN) + MIN;
            
            Console.WriteLine("{0:f1}", num);
        }

        Console.WriteLine("the average of the degres is: {0}",ex4);

And I want to calculate the average of the numbers and print it but I don't know how to store all the values that I could calculate them or if there is another way




Aucun commentaire:

Enregistrer un commentaire