#Need help understanding this code as I need to trace a modified version of it on my exam.

6 messages · Page 1 of 1 (latest)

dusk heath
#

#include <stdio.h>
#include <ctype.h>
int main() {
int index, freq[26], c, stars, maxfreq;
for (index=0; index<26; index++)
freq[index] = 0;
while ( (c = getchar()) != '7') {
if (isalpha(c))
freq[tolower(c)-'a']++;
}
maxfreq = freq[25];
for (index = 24; index >= 0; index--) {
if (freq[index] > maxfreq)
maxfreq = freq[index];
}
printf("a b c d e f\n");
for (index=0; index<5; index++) {
for (stars=0; stars< (maxfreq - freq[index]); stars++)
printf(" ");
for (stars=0; stars< (freq[index]); stars++)
printf("*");
printf("%c \n", ('A' + index) );
printf(" \n");
}
return 0;
}

I dont understand what is happening (Assumed input is aaBBcc*c7)

quasi ravenBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

quasi ravenBOT
#
#include <ctype.h>
#include <stdio.h>
int main() {
  int index, freq[26], c, stars, maxfreq;
  for (index = 0; index < 26; index++)
    freq[index] = 0;
  while ((c = getchar()) != '7') {
    if (isalpha(c))
      freq[tolower(c) - 'a']++;
  }
  maxfreq = freq[25];
  for (index = 24; index >= 0; index--) {
    if (freq[index] > maxfreq)
      maxfreq = freq[index];
  }
  printf("a b c d e f\n");
  for (index = 0; index < 5; index++) {
    for (stars = 0; stars < (maxfreq - freq[index]); stars++)
      printf(" ");
    for (stars = 0; stars < (freq[index]); stars++)
      printf("*");
    printf("%c  \n", ('A' + index));
    printf(" \n");
  }
  return 0;
}

I dont understand what is happening (Assumed input is aaBBcc*c7)

Luger
sand gyro
#

What's your current understanding of it

quasi ravenBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.