mercredi 20 avril 2022

How do you display the number that has the lowest and highest amount of duplicates in a list w/o using built in functions?

I've created a program that displays 1000 (1k) random integers with duplicates its rng range is from 1 - 1000, with that I want to know how many times a specific number has been generated with the highest and lowest frequency and display it. Ex: 51 is the number that has been generated 50 times, which is the highest (Note: I cannot use any built in function for logic building purposes)

{
        List<int> numPool = new List<int>();
        Random rnd = new Random();

        string uinput = "";

        int storage = 0;

        while (true)
        {
            // generating number pool
            for (int i = 0; i < 1000; i++)
                numPool.Add(i + 1);

            // generating 100 numbers
            Console.WriteLine("Generating 100 numbers (1-1001) with duplicates...");
            int d = 1;
            while (numPool.Count > 0)
            {
                int temp = 0;

                temp = rnd.Next(0, numPool.Count); // this generates a random index between 0 and however long the list is
                Console.Write("{0}\t", temp);
                numPool.RemoveAt(temp); // removes the index
                if (d % 10 == 0)
                Console.WriteLine();

                d++;
            }

            Console.WriteLine("Highest amount of duplicate numbers: "); // this part should show the number with the highest amount of duplicates
            Console.WriteLine("Number of times it was duplicated: "); // this part will show how many times it was duplicated
            Console.WriteLine("\nLeast amount of Duplicate numbers: "); // this part should show the number with the least amount of duplicates
            Console.WriteLine("Number of times it was duplicated: "); // this part will show how many times it was duplicated

            Console.Write("\nWhat number would you like to show the frequency?: ");
            uinput = Console.ReadLine();
            storage = int.Parse(uinput);

            // from this part it should show the number of times the duplicate number has appeared according to the user input

            //Console.WriteLine("The number " + storage + " has appeared " + insert the amount of times it has appeared + " times.");


            Console.ReadKey();
            Console.Clear();
        }
    }



Aucun commentaire:

Enregistrer un commentaire