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
(20 points) (Assessment of Outcome 1): A plant has two identical standby generator units for emergency use. In the area of the g
erastovalidia [21]

Answer:

It wouldn't get any louder then maybe 3db more

Explanation:

There's even a equation if you wanted to check this out but, if they are the same generator same model and all and made the same precise noise it wouldn't increase more then 3db.

5 0
4 years ago
A metal specimen with an original diameter of 0.50 in. and a gauge length of 2.75 in. is tested in tension until a fracture occu
tatiyna

Answer:

Percent Elongation = 52.72%

Percent Reduction in Area = 64%

Explanation:

First we find percent elongation:

Percent Elongation = {Final Gage Length - Initial Gauge Length/Initial Guage Length} x 100%

Percent Elongation = {(4.20 in - 2.75 in)/2.75 in} x 100%

<u>Percent Elongation = 52.72%</u>

Now, for the percent reduction in area:

Percent Reduction in Area = {Final Cross Sectional Area - Initial Cross Sectional Area|/Initial Cross Sectional Area Length} x 100%

Percent Reduction in Area = {π(0.3 in)² - π(0.5 in)²/π(0.5 in)²} x 100%

<u>Percent Reduction in Area = - 64%</u>

here, negative sign shows a decrease in area.

5 0
3 years ago
An incremental encoder is rotating at 15 rpm. On the wheel there are 40 holes. How many degrees of rotation would 1 pulse be?
elena-s [515]

Answer:

1 pulse rotate = 9 degree

Explanation:

given data

incremental encoder rotating = 15 rpm

wheel holes = 40

solution

we get here first 1 revolution time

as 15 revolution take = 60 second

so 1 revolution take = \frac{60}{15}

1 revolution take = 4 seconds

and

40 pulse are there for 1 revolution

40 pulse for 360 degree

so 1 pulse rotate is = \frac{360}{40}

1 pulse rotate = 9 degree

3 0
3 years ago
L+S=LEENA SAUD<br>.......​
Verdich [7]

Answer:

lol contrates brother......

6 0
3 years ago
Read 2 more answers
Which type of work is an electrical engineer most likely to do?
IRISSAK [1]
I believe A is the answer: creat materials for electrical cables

Hope this helps you have a great day
5 0
3 years ago
Read 2 more answers
Other questions:
  • what do you think the author is trying to express to society during his time of period through this story? in the open window
    9·1 answer
  • What are the x and y coordinates of the centroid of the area?
    10·1 answer
  • A 50 Ibm block is moving at 4 ft/s. Find Its total kinetic energy? Also find Its kinetic energy per unit mass is
    13·1 answer
  • Q1. A truck traveling at 40 mph is approaching a stop sign. At time ????0 and at a distance of 80ft, the truck begins to slow do
    5·2 answers
  • The convection coefficient for flow over a solid sphere may be determined by submerging the sphere, which is initially at 25 °C,
    10·1 answer
  • Calculate the convective heat-transfer coefficient for water flowing in a round pipe with an inner diameter of 3.0 cm. The water
    8·1 answer
  • A piston–cylinder device contains 15 kg of saturated refrigerant-134a vapor at 280kPa. A resistance heater inside the cylinder w
    10·1 answer
  • 10. Technician A says checking the automatic
    8·1 answer
  • Technician A says mismatching tires of the same size on a heavy vehicle will generally not affect ABS operation. Technician B sa
    13·1 answer
  • What kinds of problems or projects would a mechanical engineer work on?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!