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
Which method protects back button to retrieve old value from previous page in Struts.
Display names and numbers of employees who have 5 years or more experience and salary less than Rs.15000 using array of structures (name, number, experience and salary)
suppose we have ten members of a physical file but we want the output of last 5 members only.how to achieve that?
what is log files in qtp what is use
i am exeprienced person what is selection process
which book we learned this mantis? how many version are realsed this mantis upto now?
Is buffer size and file block size is similar? If similar,at which case it will be same size?
what is difference between input parameter and output parameter.
Always use scope terminator like End-If with IF, End- Evaluate with Evaluate statement.Can somebody explain me the detail logical explanation?
When we have two versions of the dot net installed how does the compiler know which version of DLL it has to select to an application.
write the a cl program with the following specification A. Accept 2 parameters-date and date type B. if date type is J then convert date to *MDY format C. if date type is M convert date to *JUL format 4.send a program message with the value of converted date Please explain for each with coding?
what is web configuration file
could u please also write an example of a code that involves instances from an abstract class just as u did for interfaces because u said it could also work which i really doubt. thanks
Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 2 numbers. Find the missing numbers.
Code for display the images from drive using vb 6.0?