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
Comparación de hipotecas Los Chos
aleksklad [387]

Answer:

I don't understand the language French sorry can't answer

3 0
3 years ago
Derive the following conversion factors: (a) Convert a pressure of 1 psi to kPa (b) Convert a vol ume of 1 liter to gallons (c)
kirill [66]

Answer:

a)6.8 KPa

b)0.264 gallon

c)47.84 Pa.s

Explanation:

We know that

1 lbf=  4.48 N

1 ft =0.30 m

a)

Given that

P= 1 psi

psi is called pound force per square inch.

We know that 1 psi = 6.8 KPa.

b)

Given that

Volume = 1 liter

We know that 1000 liter = 1 cubic meter.

1 liter =0.264 gallon.

c)

1\ \frac{lb.s}{ft^2}=47.84\ \frac{Pa.s}{ft^2}

4 0
3 years ago
Calculate the magnitude of the velocity and the θ angular direction of the block and the bullet together when the 50 g bullet mo
almond37 [142]

Answer:

Magnitude of the velocity = 16.82 m/s

Angular direction, θ = 52.41°

Explanation:

As given ,

mass of bullet, m₁= 50g = 0.05 kg

speed of bullet , u₁ = 600 m/s

mass of the block , m₂ = 4 kg

speed of the block before collision , u₂ = 12 m/s

direction , θ = 30°

Now,

Assume that the combined velocity of bullet and block after collision = v

and the direction = θ

Now, from the conservation of momentum in x - direction :

m₁ u₁ + m₂ u₂ = ( m₁ + m₂ ) vₓ

where v = final velocity after collision

u₁ = initial velocity of bullet before collision = 0

m₁ = mass of the bullet before collision = 0.05 kg

u₂  = velocity of block before collision = 12 cos(30° )

m₂ = mass of block before collision

m₁ + m₂ = combined mass of bullet and block after collision = 0.05 + 4

∴ we get

0.05 (0) + 4(12 cos(30° ) ) = ( 0.05 + 4 ) vₓ

⇒ 0 + 4(6√3) = 4.05 vₓ

⇒24√3 = 4.05 vₓ

⇒vₓ = 10.26 m/s

Now, from the conservation of momentum in y - direction :

m₁ u₁ + m₂ u₂ = ( m₁ + m₂ ) v_{y}

where v = final velocity after collision

u₁= initial velocity of bullet before collision = 600

m₁ = mass of the bullet before collision = 0.05 kg

u₂  = velocity of block before collision = 12 sin(30° )

m₂= mass of block before collision

m₁+ m₂= combined mass of bullet and block after collision = 0.05 + 4

∴ we get

0.05 (600) + 4(12 sin(30° ) ) = ( 0.05 + 4 ) v_{y}

⇒ 30 + 4(6) = 4.05 v_{y}

⇒30 +24 = 4.05 v_{y}

⇒54 = 4.05 v_{y}

⇒v_{y} = 13.33 m/s

Now, the magnitude of the velocity = √vₓ² + v_{y}² = √(10.26)² + (13.33)²

                                                           = √105.26 + 177.68

                                                           = √282.95 = 16.82

The angular direction, θ =  tan^{-1}(\frac{v_{y} }{v_{x} }) =  tan^{-1}(\frac{13.33}{10.26}) = tan^{-1}(1.299) = 52.41°

8 0
3 years ago
According to one government agency, bad housekeeping is estimated to cause what percentage
muminat
It’s 50 percent 99 percent sure
8 0
3 years ago
Determine the minimum necessary clearance height of the overpass and the resultant elevation of the bottom of the overpass over
Nastasia [14]

Answer:

attached below

Explanation:

5 0
3 years ago
Other questions:
  • What is matrix ? answer plzzz 27 point you got answer​
    15·2 answers
  • Write a C program that will update a bank balance. A user cannot withdraw an amount ofmoney that is more than the current balanc
    13·1 answer
  • Which of the following is true of dead zones? a. They are formed when a volcanic eruption covers the soil with ash. b. They are
    15·1 answer
  • 2. When it comes to selling their crop, what are 3 options a farmer has when harvesting their grain?
    5·1 answer
  • Cryogenic liquid storage. Liquid oxygen is stored in a thin-walled spherical container, 96 cm in diameter, which is further encl
    10·1 answer
  • Biblical studies of john​
    11·1 answer
  • You are hired as the investigators to identify the root cause and describe what should have occurred based on the following info
    9·1 answer
  • Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    9·1 answer
  • The example of using biotechnology in heart surgery is used to illustrate which of the
    12·1 answer
  • What current must flow if 0.24 coulombs is to be transferred in 15ms?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!