Tech Study

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

Introduction

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

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

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

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more