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
WHat is execution in manual testing and when will we start execution and what language we use in execution
how pseudo column works?
How to print No.of.rows affected after updation using ADO.Net
Which design patterns have you used?
i want to improve my english vocab for racking campus written exam plz tell me best book for prepration......
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..??
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?
what is the difference between an OS(operating system) and Framework?
how do i create my own exception class which will restrict IO exception?
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??/
what is d main diff between the java and .net framework
Explain the types of operations? Draw the figure for shift and rotate operations?
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
Delta 5 weight scale not connect with oracle application what i can do?
What is the meaning of client-server application. The purpose of Client-Server Application. with description.