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
I'm bored. I want to talk to you humans! weird. STUPID QUARANTINE!!! So. What are yall up to?
kiruha [24]

Answer:

nothing much what class r u in

3 0
3 years ago
Example – a 100 kW, 60 Hz, 1175 rpm motor is coupled to a flywheel through a gearbox • the kinetic energy of the revolving compo
rjkz [21]

Answer:

1200KJ

Explanation:

The heat dissipated in the rotor while coming down from its running speed to zero, is equal to three times its running kinetic energy.

P (rotor-loss) = 3 x K.E

P = 3 x 300 = 900 KJ

After coming to zero, the motor again goes back to running speed of 1175 rpm but in opposite direction. The KE in this case would be;

KE = 300 KJ

Since it is in opposite direction, it will also add up to rotor loss

P ( rotor loss ) = 900 + 300 = 1200 KJ

7 0
3 years ago
What type of building project is most like an enhanced skills occupation?
enot [183]

Answer:

4.modifying a building to achieve an entirely new purpose

8 0
3 years ago
3. Which of these instruments is used to measure wind speed? A. anemometer C. wind sock B. thermometer D. wind vane It is an ins
siniylev [52]

Answer:

wind vane if it can be used to show wind speed and the other is a

Explanation:

please mark 5 star if im right and brainly when ya can

5 0
3 years ago
A hydraulic jump is induced in an 80 ft wide channel.The water depths on either side of the jump are 1 ft and 10 ft.Please calcu
krek1111 [17]

Answer:

a) 42.08 ft/sec

b) 3366.33 ft³/sec

c) 0.235

d) 18.225 ft

e) 3.80 ft

Explanation:

Given:

b = 80ft

y1 = 1 ft

y2 = 10ft

a) Let's take the formula:

\frac{y2}{y1} = \frac{1}{5} * \sqrt{1 + 8f^2 - 1}

10*2 = \sqrt{1 + 8f^2 - 1

1 + 8f² = (20+1)²

= 8f² = 440

f² = 55

f = 7.416

For velocity of the faster moving flow, we have :

\frac{V_1}{\sqrt{g*y_1}} = 7.416

V_1 = 7.416 *\sqrt{32.2*1}

V1 = 42.08 ft/sec

b) the flow rate will be calculated as

Q = VA

VA = V1 * b *y1

= 42.08 * 80 * 1

= 3366.66 ft³/sec

c) The Froude number of the sub-critical flow.

V2.A2 = 3366.66

Where A2 = 80ft * 10ft

Solving for V2, we have:

V_2 = \frac{3666.66}{80*10}

= 4.208 ft/sec

Froude number, F2 =

\frac{V_2}{g*y_2} = \frac{4.208}{32.2*10}

F2 = 0.235

d) El = \frac{(y_2 - y_1)^3}{4*y_1*y_2}

El = \frac{(10-1)^3}{4*1*10}

= \frac{9^3}{40}

= 18.225ft

e) for critical depth, we use :

y_c = [\frac{(\frac{3366.66}{80})^2}{32.2}]^1^/^3

= 3.80 ft

7 0
3 years ago
Read 2 more answers
Other questions:
  • Describe a simple process
    11·1 answer
  • This is a blueprint drawing of the stage area at Millennium Park. The length of one square on the grid is equal to 5 feet. Accor
    14·1 answer
  • Write a function called arraySum() that takes two arguments: an integer array and the number of elements in the array. Have the
    14·1 answer
  • Estimate the time it would take for such axons to carry a message from a foot stepping on a sharp object to the brain and then b
    14·1 answer
  • The concrete canoe team does some analysis on their design and calculates that they need a compressive strength of 860 psi. They
    15·1 answer
  • Refrigerant-134a enters an adiabatic compressor at -30oC as a saturated vapor at a rate of 0.45 m3 /min and leaves at 900 kPa an
    13·1 answer
  • Determine the wattmeter reading when it is connected to resistor load.​
    11·1 answer
  • What are the risks of biohacking? Do you think the risks of biohacking outweigh the advantages? Why or why not?
    5·1 answer
  • A 60-Hz 3-phase induction motor is required to drive a load at approximately 850 rpm. How many poles should the motor have
    9·1 answer
  • Technician A says that synthetic blend oil has the same service life as that of full synthetic oils. Technician B says that conv
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!