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
If you want to obtain a Class E license before you turn 18, you must______. A. be in compliance with school attendance requireme
Makovka662 [10]

Answer:

The correct option is;

A. be in compliance with school attendance requirements

Explanation:

The requirements to acquire a special restricted driver's license for driver's license for under under 18 that have had a beginner's for up to 180 days include a minimum of 40 hours driving practice 10 of which should be in the dark. The application for the conditional drivers license is to be signed by the parent or guardian and the application is to be accompanied with proof of acceptable school attendance

At 17, after holding the special restricted drivers licence for a year without issues you can obtain the full drivers license.

7 0
3 years ago
If you deposit today 11,613 in an account earning 8% compound interest, for how long should you invest the money in order to ear
Elanso [62]
Y = a (b)^t/p

y is total money

a is original amount

b is growth / decay factor

t is time

p is the frequency of every growth or decay

15131.76 = 11613 x 1.08^x

15131.76 / 11613 = 1.08^x

1.303… = 1.08^x

log1.303…. = xlog1.08

x = 3.43902165741 years
3 0
2 years ago
An engineer designs a new bus that can drive 30 miles per gallon of fuel. Which of the following was likely one of the client’s
Marat540 [252]
What are the options?
7 0
4 years ago
Read 2 more answers
Write short notes on: (any four) a) Suspended ground floor b) Soil exploration c) Baulking of sand d) Bearing capacity of soil e
vredina [299]

Answer:

a) A suspended floor is a ground floor with a void underneath the structure. The floor can be formed in various ways, using timber joists, precast concrete panels, block and beam system or cast in-situ with reinforced concrete. However, the floor structure is supported by external and internal walls.

b) Soil exploration consists of determining the profile of the natural soil deposits at the site, taking the soil samples and determining the engineering properties of soils using laboratory tests as well as in-situ testing methods

c) Bulking in sand Occurs When dry sand interacts with the atmospheric moisture. Presence of moisture content forms a thin layer around sand particles. This layer generates the force which makes particles to move aside to each other. This results in the increase of the volume of sand.

d) In a nutshell, bearing capacity is the capacity of soil to support the loads that are applied to the ground above. It depends primarily on the type of soil, its shear strength and its density. It also depends on the depth of embedment of the load – the deeper it is founded, the greater the bearing capacity.

Explanation:

<h2>please follow me</h2>
6 0
3 years ago
As project manager, you approve a team member’s request to change the order of their tasks because they think it will be more ef
Oduvanchick [21]

The project is going to scope if the situation happens. Option A is correct.

<h3 /><h3>What is the function of a project manager?</h3>

Project managers are in charge of organizing, planning, and guiding the execution of certain projects for an organization .

As the project manager, you grant a team member's request to rearrange their work in a way they believe will increase productivity.

However, this modification interferes with another team member's workflow since they now have to complete two more activities that are unrelated to the project's objective. The project will be within its scope.

Hence option A is correct.

To learn more about the project manager refer;

brainly.com/question/15404120

#SPJ1

6 0
2 years ago
Other questions:
  • When a group of firms chooses to work together to turn a non-monopoly market into a monopoly market by securing formal agreement
    8·1 answer
  • Choose the true statement from those shown below: A Merchant Account allows you to use SSL on your web site. Disadvantages of us
    14·1 answer
  • What is the advantage of Sensabot over human inspectors?
    12·1 answer
  • Which of the following correctly explains why it would be beneficial for an engineer to become a member of the Leadership in Ene
    15·2 answers
  • As part of an insurance company’s training program, participants learn how to conduct an analysis of clients’ insurability. The
    9·1 answer
  • A motor vehicle has a mass of 1200kg and the road wheels have a radius of 360mm. The engine rotating parts have a moment of iner
    5·1 answer
  • What are the coordinates of the centroid of this figure?
    5·1 answer
  • First real answer i’ll give Brainlyist
    12·1 answer
  • What is the moment that the wrench puts on the bolt?
    13·1 answer
  • R-744 refrigerant is bad why
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!