Please Write a C# console program named Histogram that reads a list of exam scores from…
- User
Please Write a C# console program named Histogram that reads a list of exam scores from an input file midtermscores.txt that contains one score per line and then displays a histogram of those numbers, divided into the ranges 0-9, 10-19, 20-29, and so forth, up to the range containing only the value 100.
00-09: 10-19: * 20-29: * 30-39: ** 40-49: * 50-59: ***** 60-69: ******* 70-79: ***************** 80-89: ****** 90-99: ********** 100: *
- Assistant
Here is a C# code that reads the file and displays the histogram:
csharpusing System; using System.Collections.Generic; using System.IO; class Histogram { static void Main() { // Read the file List<int> scores = new List<int>(); string[] lines = File.ReadAllLines("midtermscores.txt"); foreach (string line in lines) { if (int.TryParse(line, out int score)) { scores.Add(score); } } // Count the scores in each range int[] count = new int[11]; foreach (int score in scores) { count[score/10]++; } // Display the histogram for (int i = 0; i < 10; i++) { Console.WriteLine($"{i * 10:00}-{i * 10 + 9:00}: {new string('*', count[i])}"); } Console.WriteLine($" 100: {new string('*', count[10])}"); } }