Use the instructions provided I will rate the answer Name th

Use the instructions provided
I will rate the answer
Name the files, bonus.c and bonus.h char highestFreq(char *str) this funetion should return the highest frequency character e in the string. For example, a call to this function with the string \"Hello World\", would return \"1\",

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.

#include \"stdio.h\"

char highestFreq(char *str){
   int count=0,ct,i,j;   //initialize variables
   char c;
   for(i=0; str[i]!=NULL; i++){   //iterate over the string : main loop
       ct = 0;   //set counter for current char as 0
       for(j=i; str[j]!=NULL; j++){   //count the no:of occurence of current char
           if(str[i]==str[j])
               ct++;
       }  
       if(ct > count){   //if current char\'s occurence is > count, then set count as current occurence and c as current char
           count = ct;
           c = str[i];
       }
   }
   return c;   //return c  
}

int main(void) {

char hf = highestFreq(\"Hello World\");
printf(\"highestFreq char = %c\",hf);
return 0;
}

--------------------------------------------------------

OUTPUT;

Use the instructions provided I will rate the answer Name the files, bonus.c and bonus.h char highestFreq(char *str) this funetion should return the highest fre

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site