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
Iam using Microsoft Visual Studio to create a system for mobile store I want to know how to calculate mobile price that the customer buy and how to reduce quantity from the data base that we have for mobile .And also how to calculate revnue for each mobile and revnue for the total mobile
what are resources in case of Threads
Find out the roles which gives access to all tables in SAP? Thanks in advance.
5. How do you round the addition or subtraction of two numbers in assembler?
When we use Windows authentication mode
could you please tell me how to draw the calibration curve for HPLC {the software which we are using}?
can we retrieve only integer/String type columns from a table,if yes how?
Delta 5 weight scale not connect with oracle application what i can do?
code for connection from windows forms to sql server
What is diffrent between Method and and function in c#
Write a program to find factorial of a number using functions
how to display xisheet in list box in c# .net
Always use scope terminator like End-If with IF, End- Evaluate with Evaluate statement.Can somebody explain me the detail logical explanation?
Difference between delegates and Events?
what are all the validation we need to perform in data stage?