//Write a program that generates 20 random integers between 0 and 9 and displays the count for each number. //Use an array of ten integers, say counts, to store the counts for the number of 0s, 1s, ..., 9s.) var random = new Random(); int[] numbers = new int[20]; int[] counts = new int[10]; Console.WriteLine("Numbers Generated: "); for (int i = 0; i < numbers.Length; i++) { numbers[i] = random.Next(0, 9); Console.WriteLine($"{numbers[i]}"); counts[numbers[i]]++; } for (int i = 0; i < counts.Length; i++) { Console.WriteLine($"Number of {i}'s: {counts[i]}"); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter