What does this code do?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AngelinaF2003
    New Member
    • Dec 2020
    • 1

    #1

    What does this code do?

    Code:
    char F10(char c[])
     { char m,z; int n,s,i;
       for (s=0,m='A'; m <='Z'; m++) {
                  for (n=0, i=0; c[i] !='\0'; i++)
                               if (c[i]==m) n++;
                               if (n > s) { z=m; s=n; }
                  }
     return z; }
    Last edited by Niheel; Dec 13 '20, 02:57 PM.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You should come up with some example strings and step through it using pen and paper.

    Some hints/offhand observations: the ifs can't be combined, the second if can be outside the inner loop, it would be more efficient to tabulate the results and get rid of the nested loops.

    Comment

    Working...