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
Tech A says that the brake pedal uses leverage to multiply foot pressure. Tech B says that when braking hard while moving
Nikolay [14]

Tech- A is correct

Explanation:

  • Leverage is defined as using a tool to gain mechanical influence. The measure of the benefit gained depends on what kind of lever is used and how it is utilized.
  • Leverage is designed in such a way that it can reproduce the force from your leg many times before any force is transferred to brake fluid.
  • The brake pedal size and the measure of leverage received depends on the overall design of the brake system.
  • The second-order lever is used in the brake pedal. The brake pedal applies leverage to populate the force employed to the master cylinder. The effort needed to drive a load depends on the corresponding distance of the load and the work from the fulcrum. The proportion of load and work is known as mechanical advantage.
7 0
4 years ago
Marco is an Italian architect. He has recieved a contract
kirill [66]

Answer:

Marco is an Italian architect. He has received a contract to design a spacious building.

Explanation:

ect.

8 0
3 years ago
In order to tell whether the lubrication system is working properly, check the
kvv77 [185]
Metering valves. These valves should be initially adjusted to provide adequate lubrication to each location
8 0
2 years ago
Technician A says that a seal can be pried out of a bore using a sharp chisel. Technician B says that smaller metal-backed seals
attashe74 [19]

Answer:

The correct answer is letter "C": Both.

Explanation:

Industrial seals are used at interfaces between components to prevent leakage, to maintain heat, and to avoid contamination. The design, construction, and materials they use vary depending on industrial use but the most common are Polytetrafluoroethylene (PTFE), Nitrile Buna Rubber (NBR), and fluorocarbon.

Thus, using a sharp chisel could pry a seal out of a hole and a regular socket can often be used to force smaller metal-backed seals into place. Thus, technicians "A" and "B" are correct.

6 0
3 years ago
Read 2 more answers
What is characteristic of a design-build approach for construction projects?
Ivenika [448]
Okey du we went on a date lastnight and all okay


Fast sheet
6 0
4 years ago
Other questions:
  • The following electrical characteristics have been determined for both intrinsic and p-type extrinsic gallium antimonide (GaSb)
    12·1 answer
  • Describe three differences between liquids and gases in fluid power systems.<br> Help !!!
    5·1 answer
  • A four-lane freeway (two lanes in each direction) is located on rolling terrain and has 12-ft lanes, no lateral obstructions wit
    14·1 answer
  • Write a program to input 6 numbers. After each number is input, print the biggest of the numbers entered so far.
    12·1 answer
  • he Weather Channel reports that it is a hot, muggy day with an air temperature of 90????F, a 10 mph breeze out of the southwest,
    6·1 answer
  • Water discharging into a 10-m-wide rectangular horizontal channel from a sluice gate is observed to have undergone a hydraulic j
    12·1 answer
  • What is the moment that the wrench puts on the bolt?
    13·1 answer
  • Consider the function f(x)=/x/
    5·1 answer
  • What do u mean by double entry bookkeeping system?<br>u fellas don't spam pls​
    12·2 answers
  • 9. What power tool incorporates a set of dies and punches to cut new
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!