A string of charaters were given. Find the highest
occurance of a character and display that character.
eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE

Answer Posted / aman bhullar

#include<string.h>
#include<stdio.h>


char HighestCharCount(char* str)
{

int length = strlen(str);
if (length == 0)
return ' ';
if (length == 1)
return str[0];

int indexOfHighest = -1;
int highestCounter = 0;
int i, j ,current = 0;
char test;
for ( i=0; i < length; ++i)
{
test = str[i];

for (j=i+1; j < length ; ++j)
{
if (str[j] == test)
{
current++;
}

if (current > highestCounter)
{
highestCounter = current;
indexOfHighest = i;
}
}
}
return str[indexOfHighest];
}

void main ( )
{
char a[] = "AEGBCNAvNEETGUPTAEDAGPE";
char res;
res = HighestCharCount(a);
printf("\n %c ", res);

}

Is This Answer Correct ?    9 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

WHat is execution in manual testing and when will we start execution and what language we use in execution

1480


how pseudo column works?

1716


How to print No.of.rows affected after updation using ADO.Net

2474


Which design patterns have you used?

1546


i want to improve my english vocab for racking campus written exam plz tell me best book for prepration......

1704






I want to insert date in the form of yyyy-mm-dd... if any changes happen while inserting date format want to show error meg...any one can solve this..??

1655


Given an array of size n+1 which contains all the numbers from 1 to n.Find the number which is repeated in O(n) time.How do you proceed with the same with floating numbers from 0 to 1 instead of 1 to n?

601


what is the difference between an OS(operating system) and Framework?

1514


how do i create my own exception class which will restrict IO exception?

2297


we create a pf with 3 fields.2 is defined as keyfields.we lock it with alcobj command.how we find out whether the file is locked or not?is it dspfd??/

1614


what is d main diff between the java and .net framework

1544


Explain the types of operations? Draw the figure for shift and rotate operations?

2799


How to connect to ms word wit VB ojective is to prepare s/w to generate question paper , selects questions randomly from the ms access , database

2006


Delta 5 weight scale not connect with oracle application what i can do?

1804


What is the meaning of client-server application. The purpose of Client-Server Application. with description.

1647