Q:

Write a C# program to find maximum occurring character in a string

0

Write a C# program to find maximum occurring character in a string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
public class Exercise10
{
    public static void Main()
    {
        string str;
        int[] frequency = new int[255];
        int i = 0, max, l;
        int ascii;
 
        Console.Write("Enter the string : ");
        str = Console.ReadLine();
        l = str.Length;
 
        for (i = 0; i < 255; i++)  
        {
            frequency[i] = 0;
        }
        // Reading frequency of each characters 
        i = 0;
        while (i < l)
        {
            ascii = (int)str[i];
            frequency[ascii] += 1;
 
            i++;
        }
 
        max = 0;
        for (i = 0; i < 255; i++)
        {
            if (i != 32)
            {
                if (frequency[i] > frequency[max])
                    max = i;
            }
        }
        Console.Write("The Highest frequency of character '{0}' is appearing for number of times : {1} \n\n", (char)max, frequency[max]);
 
        Console.ReadLine();
    }
}

Result:

Enter the string : techstudy.org

The Highest frequency of character 't' is appearing for number of times : 2 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a C# program to read a string through the ke... >>
<< Write a C# program to count a total number of vowe...