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
In the circuit given below, R1 = 17 kΩ, R2 = 74 kΩ, and R3 = 5 MΩ. Calculate the gain 1formula58.mml when the switch is in posit
Elenna [48]

Answer:a

a) Vo/Vi = - 3.4

b) Vo/Vi = - 14.8

c) Vo/Vi = - 1000

Explanation:

a)

R1 = 17kΩ

for ideal op-amp

Va≈Vb=0 so Va=0

(Va - Vi)/5kΩ + (Va -Vo)/17kΩ = 0

sin we know Va≈Vb=0

so

-Vi/5kΩ + -Vo/17kΩ = 0

Vo/Vi = - 17k/5k

Vo/Vi = -3.4

║Vo/Vi ║ = 3.4    ( negative sign phase inversion)

b)

R2 = 74kΩ

for ideal op-amp

Va≈Vb=0 so Va=0

so

(Va-Vi)/5kΩ + (Va-Vo)74kΩ = 0

-Vi/5kΩ + -Vo/74kΩ = 0

Vo/Vi = - 74kΩ/5kΩ

Vo/Vi = - 14.8

║Vo/Vi ║ = 14.8  ( negative sign phase inversion)

c)

Also for ideal op-amp

Va≈Vb=0 so Va=0

Now for position 3 we apply nodal analysis we got at position 1

(Va - Vi)/5kΩ + (Va - Vo)/5000kΩ = 0           ( 5MΩ = 5000kΩ )

so

-Vi/5kΩ + -Vo/5000kΩ = 0

Vo/Vi = - 5000kΩ/5kΩ

Vo/Vi = - 1000

║Vo/Vi ║ = 1000  ( negative sign phase inversion)

3 0
3 years ago
DRIVERS ED
forsale [732]

Answer:

b

Explanation:

only if there signal is turned on

8 0
3 years ago
Read 2 more answers
Science, Technology, Engineering &amp; Mathematics
miv72 [106K]

A communication systems

4 0
3 years ago
An Ideal gas is being heated in a circular duct as while flowing over an electric heater of 130 kW. The diameter of duct is 500
max2010maxim [7]

Answer: The exit temperature of the gas in deg C is 32^{o}C.

Explanation:

The given data is as follows.

C_{p} = 1000 J/kg K,   R = 500 J/kg K = 0.5 kJ/kg K (as 1 kJ = 1000 J)

P_{1} = 100 kPa,     V_{1} = 15 m^{3}/s

T_{1} = 27^{o}C = (27 + 273) K = 300 K

We know that for an ideal gas the mass flow rate will be calculated as follows.

     P_{1}V_{1} = mRT_{1}

or,         m = \frac{P_{1}V_{1}}{RT_{1}}

                = \frac{100 \times 15}{0.5 \times 300}

                = 10 kg/s

Now, according to the steady flow energy equation:

mh_{1} + Q = mh_{2} + W

h_{1} + \frac{Q}{m} = h_{2} + \frac{W}{m}

C_{p}T_{1} - \frac{80}{10} = C_{p}T_{2} - \frac{130}{10}

(T_{2} - T_{1})C_{p} = \frac{130 - 80}{10}

(T_{2} - T_{1}) = 5 K

T_{2} = 5 K + 300 K

T_{2} = 305 K

           = (305 K - 273 K)

           = 32^{o}C

Therefore, we can conclude that the exit temperature of the gas in deg C is 32^{o}C.

7 0
3 years ago
During his military campaign in what is now Germany, Julius Caesar lead his army of 40,000 soldiers to the western bank of the R
CaHeK987 [17]

Answer:

identifying a problem

Explanation:

its right

5 0
3 years ago
Other questions:
  • Time complexity of merge sort
    15·1 answer
  • A fluid of specific gravity 0.96 flows steadily in a long, vertical 0.71-in.-diameter pipe with an average velocity of 0.90 ft/s
    5·2 answers
  • Selling a new vehicle pays a salesperson $1500. Selling a used vehicle pays a commission of 5% of the selling price. Write an in
    9·1 answer
  • Trees grow in bulk in outward direction​
    9·1 answer
  • Compare the temperature dependence of Nabarro-Herring and Coble creep. Which is more temperature-sensitive
    15·1 answer
  • Describe in detail the process of making a collapsable bowl.​
    11·1 answer
  • What are the nine Historical periods?
    9·1 answer
  • 3.
    7·1 answer
  • your friend's parents are worried about going over their budget for th month. Which expense would you suggest is NOT a need?
    9·1 answer
  • A cantilever beam AB of length L has fixed support at A and spring support at B.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!