Question

4. [8] Write a C function with prototype · void letter_freq(const char word[], int freq []); This function computes the numbe
u also need to store the letters' ASCII number in the freq array
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here Iam providing the code and the output to the given problem.

Code:-

#include <stdio.h> #include<string . h> #include<ctype.h> void letter_freq(char word[], char UpperCase[] , char LowerCase [ ]

Code in text format:-

#include <stdio.h>
#include<string.h>
#include<ctype.h>
void letter_freq(char word[] , char UpperCase[] , char LowerCase[]); //function declaration

int main()
{
char word[100] , UpperCase[26] , LowerCase[26]; //declaring arrays
printf("Enter the word :");
scanf("%s" , word); //storing the input
int i;
for ( i = 0 ; i<= 26 ; i++){ //taking initial values of arrays as 0
UpperCase[i] =0;
LowerCase[i] =0;
}
  
letter_freq(word ,UpperCase ,LowerCase); //function calling

}

void letter_freq(char word[] , char UpperCase[] , char LowerCase[]){
  
int i , word_lenght,index;
word_lenght = strlen(word);//calculating word length
  
for( i =0 ; i < word_lenght ; i++){ //looping through the word length
if(word[i] >= 65 && word[i] <= 90 ){ // if the letter is Capital
index = word[i] - 'A'; //taking the index
UpperCase[index] = UpperCase[index]+1; //counting the repeated times and storing
}
else{ //if letter is LowerCase
  
index = word[i] - 'a';
LowerCase[index] = LowerCase[index]+1; //counting the repeated times and storing
}
  
}
for(i = 0 ; i<26 ; i++){
printf("The count of %c and %c is %d and %d\n " , i+65 , i+97 ,UpperCase[i] , LowerCase[i]);//printing the result
}
  
  
  
  
  
}

  
  
Output:-

Enter the word :ABCDab
The count of A and a is 1 and 1
The count of B and b is 1 and 1
The count of C and c is 1 and 0
The count of D and d is 1 and 0
The count of E and e is 0 and 0
The count of F and f is 0 and 0
The count of G and g is 0 and 0
The count of H and h is 0 and 0
The count of I and i is 0 and 0
The count of J and j is 0 and 0
The count of K and k is 0 and 0
The count of L and l is 0 and 0
The count of M and m is 0 and 0
The count of N and n is 0 and 0
The count of O and o is 0 and 0
The count of P and p is 0 and 0
The count of Q and q is 0 and 0
The count of R and r is 0 and 0
The count of S and s is 0 and 0
The count of T and t is 0 and 0
The count of U and u is 0 and 0
The count of V and v is 0 and 0
The count of W and w is 0 and 0
The count of X and x is 0 and 0
The count of Y and y is 0 and 0
The count of Z and z is 0 and 0

Add a comment
Know the answer?
Add Answer to:
u also need to store the letters' ASCII number in the freq array 4. [8] Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This...

    4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This function computes the number of appearances of each letter in the string word and stores them irn array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90 for the uppercase letters. You must account for uppercase and lowercase letter variants, which...

  • Write a C++ console application that reverses an array of characters, and counts the number of:...

    Write a C++ console application that reverses an array of characters, and counts the number of:           Lower case characters (islower)           Upper case characters (isupper)           Digits (isdigit)           Other (not one of previous) Create four global variables to hold these counts. Create function void count(char input[], char reverse[]) that takes as input two arrays: one that contains characters and another that will contain the reverse of that array. The function will reverse the input array and do the...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

  • 6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you...

    6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...

  • in c, 5. Write a function that tests whether two words are anagrams. The function returns...

    in c, 5. Write a function that tests whether two words are anagrams. The function returns 1 if the two words are anagrams, returns 0 otherwise. Two words are anagrams if they are permutations of the same letters. For example, smartest and mattress are anagrams and dumbest and stumble are not anagrams. Assume wordl and word2 are null-terminated strings containing arbitrary lower-case alphabetic letters. Hint: use an array of 26 integers to keep track of how many times each letter...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • Programming language --> Matlab The name of a text file Outputs: (cell) An Nx2 cell array...

    Programming language --> Matlab The name of a text file Outputs: (cell) An Nx2 cell array listing words and their counts in sorted order Function Description: Have you ever seen those fancy word-clouds based on the frequency of word occurrences in some text? Well the first step of making a graphic like that is to figure out how often the words in some text occur, which is exactly what this function will do. You will count the number of occurrences...

  • Assignment 1 In this assignment you will be writing a tool to help you play the...

    Assignment 1 In this assignment you will be writing a tool to help you play the word puzzle game AlphaBear. In the game, certain letters must be used at each round or else they will turn into rocks! Therefore, we want to create a tool that you can provide with a list of letters you MUST use and a list of available letters and the program returns a list of all the words that contain required letters and only contain...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT