1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
choli [55]
3 years ago
5

You are given a C program "q2.c" as below. This program is used to calculate the average word length for a sentence (a string in

a single line): Enter a sentence: It was deja vu all over again. Average word length: 3.42 For simplicity, the program considers a punctuation mark to be part of the word to which it is attached. And it displays the average word length to two decimal places.
Engineering
1 answer:
MrMuchimi3 years ago
5 0

Answer:

  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5.    char sentence[100];
  6.    int i;
  7.    int wordCount = 1;
  8.    int charCount = 0;
  9.    float averageLength;
  10.    
  11.    printf("Enter a sentence: ");
  12.    gets(sentence);
  13.    
  14.    for(i = 0; i < strlen(sentence); i++){
  15.        if(sentence[i] != ' '){
  16.            charCount++;
  17.        }else{
  18.            wordCount++;
  19.        }    
  20.    }
  21.    
  22.    averageLength = (float)charCount / wordCount;
  23.    printf("Average word length: %.2f", averageLength);
  24.    
  25.    return 0;
  26. }

Explanation:

Firstly we need to import the string.h library  as we need to use strlen method to estimate the length of the input string (Line 2).

To estimate the average word length for an input sentence, we can calculate the total of characters in the sentence and then divide it by the total number of words. To do so, we first get the input sentence from the user (Line 11-12). Next, use a for loop to traverse through the sentence character by character and check if the character is not a space ' ', increment charCount by one. Whenever there is a space, this mark an end of a word and therefore increment wordCount by one (Line 18).

After the loop, we can calculate the average word length by dividing the charCount by wordCount and print the output to two decimal places (Line 22- 23).  

You might be interested in
Which investigative process is most helpful for learning about past societies?
tatuchka [14]

Answer: think it A

Explanation: makes

6 0
3 years ago
Construction support involves mostly what kind of work?
Paraphin [41]

Answer:

Outdoors

Explanation:

Construction workers perform outdoors.

6 0
2 years ago
A microwave transmitter has an output of 0.1W at 2 GHz. Assume that this transmitter is used in a microwave communication system
Len [333]

Answer:

gain = 353.3616

P_r = 1.742*10^-8 W

Explanation:

Given:

- The output Power P_o = 0.1 W

- The diameter of the antennas d = 1.2 m

- The frequency of signal f = 2 GHz

Find:

a. What is the gain of each antenna?

b. If the receiving antenna is located 24 km from the transmitting antenna over a free space path, find the available signal power out of the receiving antenna.

Solution:

- The gain of the parabolic antenna is given by the following formula:

                            gain = 0.56 * 4 * pi^2 * r^2 / λ^2

Where, λ : The wavelength of signal

            r: Radius of antenna = d / 2 = 1.2 / 2 = 0.6 m

- The wavelength can be determined by:

                            λ = c / f

                            λ = (3*10^8) / (2*10^9)

                            λ = 0.15 m

- Plug in the values in the gain formula:

                            gain = 0.56 * 4 * pi^2 * 0.6^2 / 0.15^2

                            gain = 353.3616

- The available signal power out from the receiving antenna is:

                            P_r = (gain^2 * λ^2 * W) / (16*pi^2 * 10^2 * 10^6)

                            P_r = (353.36^2 * 0.15^2 * 0.1) / (16*pi^2 * 10^2 * 10^6)

                            P_r = 1.742*10^-8 W

4 0
3 years ago
Explain when it is appropriate to use Tier II?
garik1379 [7]

????? what do u mean tier 2

3 0
2 years ago
NO LINK plsssss just answer
solmaris [256]

Answer:

Explanation:

4 0
2 years ago
Other questions:
  • Determine the angular acceleration of the uniform disk if (a) the rotational inertia of the disk is ignored and (b) the inertia
    11·1 answer
  • A curve with 0.3 m constant radius contains a bead that is moving on it such that its rotational velocity is 3t2 sec-1. If the b
    12·1 answer
  • Nitrogen can be liquefied using a Joule-Thomson expansioni process. This is done by rapidlyl and adiabatically expandign cold ni
    15·1 answer
  • Which of the code pieces below should replace the underline?public class Test{public static void main(String[] args){Test test =
    8·1 answer
  • The human body gets its energy via the combustion of blood sugar (glucose). if all of the chemical bond energy in 10 g of glucos
    9·1 answer
  • Two mass streams of the same ideal gas are mixed in a steady-flow chamber while receiving energy by heat transfer from the surro
    11·1 answer
  • Anne-Marie Cole runs the sales division for a local auto insurance firm. One of her key duties is to calculate her company's mar
    11·2 answers
  • 10. Identify one material we Mine and what we make with that material
    6·1 answer
  • While discussing the diagnosis of an EI system in which the crankshaft and camshaft sensor tests are satisfactory but a spark te
    13·1 answer
  • ____ grinders are used to grind diameters, shoulders, and faces much like the lathe is used for turning, facing, and boring oper
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!