467,166 Members | 1,021 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,166 developers. It's quick & easy.

What does this code do?

Expand|Select|Wrap|Line Numbers
  1. char F10(char c[])
  2.  { char m,z; int n,s,i;
  3.    for (s=0,m='A'; m <='Z'; m++) {
  4.               for (n=0, i=0; c[i] !='\0'; i++)
  5.                            if (c[i]==m) n++;
  6.                            if (n > s) { z=m; s=n; }
  7.               }
  8.  return z; }
  9.  
  10.  
Dec 13 '20 #1
  • viewed: 1432
Share:
1 Reply
Rabbit
Expert Mod 8TB
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.
Dec 13 '20 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

70 posts views Thread by Roy Yao | last post: by
8 posts views Thread by Kim Forbes | last post: by
13 posts views Thread by Protoman | last post: by
92 posts views Thread by Heinrich Pumpernickel | last post: by
9 posts views Thread by James Dow Allen | last post: by
3 posts views Thread by qianz99@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.