max occuring char in a string
Sun Oct 12 2025 13:29:31 GMT+0000 (Coordinated Universal Time)
Saved by
@robo
using System;
class MaxOccurringChar
{
static void Main()
{
Console.Write("Enter a string: ");
string str = Console.ReadLine();
int[] freq = new int[256];
foreach (char c in str)
freq[c]++;
int max = 0;
char result = ' ';
foreach (char c in str)
{
if (freq[c] > max)
{
max = freq[c];
result = c;
}
}
Console.WriteLine($"Maximum occurring character: {result}");
}
}
content_copyCOPY
Comments