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
What is hardness and how is it generally tested?
drek231 [11]

Answer:

Hardness is understood as the property of materials in general to resist the penetration of an indenter under load, so that the hardness represents the resistance of the material to the plastic deformation located on its surface.

Explanation:

Hardness of a material is understood as the resistance that the material opposes to its permanent surface plastic deformation by scratching or penetration. It is always true that the hardness of a material is inversely proportional to the footprint that remains on its surface when a force is applied.

In this sense, the hardness of a material can also be defined as that property of the surface layer of the material to resist any elastic deformation, plastic or destruction due to the action of local contact forces caused by another body (called indenter or penetrator), harder, of certain shape and dimensions, which does not suffer residual deformations during contact.

That is, hardness is understood as the property of materials in general to resist the penetration of an indenter under load, so that the hardness represents the resistance of the material to the plastic deformation located on its surface.

The following conclusions can be drawn from the previous definition of hardness:  

  1) hardness, by definition, is a property of the surface layer of the material, and is not a property of the material itself;  

  2) the methods of hardness by indentation presuppose the presence of contact efforts, and therefore, the hardness can be quantified within a scale;

  3) In any case, the indenter or penetrator must not undergo residual deformations during the test of hardness measurement of the body being tested.

To determine the hardness of the materials, durometers with different types of tips and ranges of loads are used on the various materials. Below are the most commonly used tests to determine the hardness of the materials.

   Rockwell hardness :

It refers to the Rockwell hardness test, a method with which the hardness or resistance of a material to be penetrated is calculated. It is characterized by being a fast and simple method that can be applied to all types of materials. An optical reader is not required.

    Brinell hardness :

Brinell hardness is a scale that is used to determine the hardness of a material through the indentation method, which consists of penetrating with a hardened steel ball tip into the hard material, a load and for a certain time.  

This test is not very precise but easy to apply. It is one of the oldest and was proposed in 1900 by Johan August Brinell, a Swedish engineer.

    Vickers hardness:

Vickers hardness is a test that is used in all types of solid and thin or soft materials. In this test, a square-shaped pyramid-shaped diamond and a   136° vertex angle are placed on the penetrating equipment.

In this test the hardness measurement is performed by calculating the diagonal penetration lengths.

However, its result is not read directly on the equipment used, therefore, the following formula must be applied to determine the hardness of the material: HV = 1.8544 · F / (dv2).

3 0
3 years ago
A four-cylinder, four-stroke internal combustion engine has a bore of 3.7 in. and a stroke of 3.4 in. The clearance volume is 16
abruzzese [7]

Answer:

1) The three possible assumptions are

a) All processes are reversible internally

b) Air, which is the working fluid circulates continuously in a closed loop

cycle

c) The process of combustion is depicted as a heat addition process

2) The diagrams are attached

5) The net work per cycle is 845.88 kJ/kg

The power developed in horsepower ≈ 45374 hP

Explanation:

1) The three possible assumptions are

a) All processes are reversible internally

b) Air, which is the working fluid circulates continuously in a closed loop

cycle

c) The process of combustion is depicted as a heat addition process

2) The diagrams are attached

5) The dimension of the cylinder bore diameter = 3.7 in. = 0.09398 m

Stroke length = 3.4 in. = 0.08636 m.

The volume of the cylinder v₁= 0.08636 ×(0.09398²)/4 = 5.99×10⁻⁴ m³

The clearance volume = 16% of cylinder volume = 0.16×5.99×10⁻⁴ m³

The clearance volume, v₂  = 9.59 × 10⁻⁵ m³

p₁ = 14.5 lbf/in.² = 99973.981 Pa

T₁ = 60 F = 288.706 K

\dfrac{T_{2}}{T_{1}} = \left (\dfrac{v_{1}}{v_{2}}  \right )^{K-1}

Otto cycle T-S diagram

T₂ = 288.706*6.25^{0.393} = 592.984 K

The maximum temperature = T₃ = 5200 R = 2888.89 K

\dfrac{T_{3}}{T_{4}} = \left (\dfrac{v_{4}}{v_{3}}  \right )^{K-1}

T₄ = 2888.89 / 6.25^{0.393} = 1406.5 K

Work done, W = c_v×(T₃ - T₂) - c_v×(T₄ - T₁)

0.718×(2888.89  - 592.984) - 0.718×(1406.5 - 288.706) = 845.88 kJ/kg

The power developed in an Otto cycle = W×Cycle per second

= 845.88 × 2400 / 60  = 33,835.377 kW = 45373.99 ≈ 45374 hP.

8 0
3 years ago
Which of the following types of protection is an employer required to pay for?
77julia77 [94]

Answer:

Hearing protection would be your answer!

Explanation:

This includes earplugs,muffs etc.

Hope it helps!

7 0
3 years ago
Read 2 more answers
If a car sits out in the sun every day for a long time can light from the sun damage the car paint
Reika [66]

Answer:

i think yes it could make the color go lighter

Explanation:

6 0
3 years ago
Read 2 more answers
Affect the amount and rate the alcohol reaches the<br> bloodstream.
just olya [345]

Answer:

Answer to the following question is as follows;

Explanation:

The amount of alcohol consumption can be influenced by a variety of things, including food.

The proportion and pace at which alcohol reaches the circulation is affected by drinking rate, body mass, and the size of the beverage. Alcohol enters your system as soon as it reaches that first sip, as per the National Institute on Drug Abuse and Alcoholism. After 10 minutes, the results are noticeable.

6 0
3 years ago
Other questions:
  • Evan notices a small fire in his workplace. Since the fire is small and the atmosphere is not smoky he decides to fight the fire
    10·1 answer
  • Find the thickness of the material that will allow heat transfer of 6706.8 *10^6 kcal during the 5 months through the rectangle
    8·1 answer
  • If the value of the feedback resistor in the filter is changed but the value of the resistor in the forward path is unchanged, w
    14·1 answer
  • Question 54 (1 point)
    11·2 answers
  • A natural-draft cooling tower receives 250,000 ft3/min of air at standard atmospheric pressure, 70oF, and 45 percent relative hu
    8·1 answer
  • Finally you will implement the full Pegasos algorithm. You will be given the same feature matrix and labels array as you were gi
    12·1 answer
  • A closed system consisting of 4 lb of a gas undergoes a process during which the relation between pressure and volume is pVn 5 c
    7·1 answer
  • Technician A says that the distributor cap provides a connection point between the rotor and each individual cylinder plug wire.
    10·1 answer
  • A technician is building a high-performance gaming pc. which two items should the technician focus on selecting parts for the ma
    8·1 answer
  • D
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!