using System; class Program { static void Main() { Console.Write("Enter a string: "); string str = Console.ReadLine().ToLower(); int[] freq = new int[256]; foreach (char ch in str) { if (ch != ' ') freq[ch]++; } int max = 0; char maxChar = ' '; for (int i = 0; i < 256; i++) { if (freq[i] > max) { max = freq[i]; maxChar = (char)i; } } Console.WriteLine("Maximum occurring character: " + maxChar); Console.WriteLine("Occurrences: " + max); } }
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