In: Computer Science
Write a C program named as listLetterFreq.c that lists the frequency of the letters from the input via ignoring the case sensitivity. For example, sample outputs could be like below.
Please input a string:
This is a list of courses. CSC 1010 - COMPUTERS & APPLICATION
Here is the letter frequency:
Letter a or A appears 3 times
Letter b or B appears 0 times
Letter c or C appears 5 times
Letter d or D appears 0 times
Letter e or E appears 2 times
Letter f or F appears 1 times
Letter g or G appears 0 times
Letter h or H appears 1 times
Letter i or I appears 5 times
Letter j or J appears 0 times
Letter k or K appears 0 times
Letter l or L appears 2 times
Letter m or M appears 1 times
Letter n or N appears 1 times
Letter o or O appears 4 times
Letter p or P appears 3 times
Letter q or Q appears 0 times
Letter r or R appears 2 times
Letter s or S appears 8 times
Letter t or T appears 4 times
Letter u or U appears 2 times
Letter v or V appears 0 times
Letter w or W appears 0 times
Letter x or X appears 0 times
Letter y or Y appears 0 times
Letter z or Z appears 0 times
C PROGRAM ====>
#include <stdio.h>
int main() {
char str[1000]; // max size is 1000
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
char str1[] = "abcdefghijklmnopqrstuvwxyz"; // alphabets in
small letter
char str2[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // alphabets in capital
letter
for(int i=0;i<26;i++)
{
int count=0;
for (int j = 0; str[j] != '\0'; ++j)
{
if (str1[i] == str[j] || str2[i] == str[j]) // compare character of
str with str1 and str2
{
++count;
}
}
printf("Letter %c or %c appears %d
times\n",str1[i],str2[i],count);
}
return 0;
}
OUTPUT SCREENSHOT ===>