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
piston-cylinder assembly contains water vapor, initially at 10 bar and 360 degC. The water undergoes a process where pv=constant
DIA [1.3K]

Answer:

Check the explanation

Explanation:

A diagrams showing the process in p-v and T-s and the Model engineering <u><em>(which is the quest in constructing miniature working representations of proportionally-scaled in full-sized machines. It is a subdivision of metalworking with a sharp importance on artisanry, in contrast to mass production.)</em></u> can be seen in the attached images below.

3 0
3 years ago
What is the built-in pollution control system in an incinerator called
Kobotan [32]

Explanation:

hbyndbnn☝️

7 0
3 years ago
Air flows through a device such that the stagnation pressure is 0.4 MPa, the stagnation temperature is 400°C, and the velocity i
RoseWind [281]

To solve this problem it is necessary to apply the concepts related to temperature stagnation and adiabatic pressure in a system.

The stagnation temperature can be defined as

T_0 = T+\frac{V^2}{2c_p}

Where

T = Static temperature

V = Velocity of Fluid

c_p = Specific Heat

Re-arrange to find the static temperature we have that

T = T_0 - \frac{V^2}{2c_p}

T = 673.15-(\frac{528}{2*1.005})(\frac{1}{1000})

T = 672.88K

Now the pressure of helium by using the Adiabatic pressure temperature is

P = P_0 (\frac{T}{T_0})^{k/(k-1)}

Where,

P_0= Stagnation pressure of the fluid

k = Specific heat ratio

Replacing we have that

P = 0.4 (\frac{672.88}{673.15})^{1.4/(1.4-1)}

P = 0.399Mpa

Therefore the static temperature of air at given conditions is 72.88K and the static pressure is 0.399Mpa

<em>Note: I took the exactly temperature of 400 ° C the equivalent of 673.15K. The approach given in the 600K statement could be inaccurate.</em>

3 0
3 years ago
Cool water at 15°C is throttled from 5(atm) to 1(atm), as in a kitchen faucet. What is the temperature change of the water? What
Tresset [83]

Answer:

the lost work per kilogram of water for this everyday household happening = 0.413 kJ/kg

Explanation:

Given that:

Initial Temperature T_1 = 15°C

Initial Pressure P_1 = 5 atm

Final Pressure P_2 = 1 atm

Data obtain from steam tables of saturated water at  15°C are as follows:

Specific volume  v = 1.001 cm³/gm

The change in temperature = 2°C

Specific heat of water = 4.19 J/gm.K

volume expansivity β = 1.5 × 10⁻⁴ K⁻¹

The expression to determine the change in temperature can be given as :

\delta \ T = \frac{-V (1- \beta \ T}{C_p} * \delta \ P ( \frac{1}{9.87} \ \frac{J}{cm^3/atm})\delta \ T = \frac{-1.001 \frac{cm^3}{gm} (1- 1.5*10^{-4} \  K^{-1} )*2}{4.19 \ \frac{J}{gm.K}} *(5-1)atm ( \frac{1}{9.87} \ \frac{J}{cm^3/atm})

Δ T = 0.093 K

Now; we can calculate the lost work bt the formula:

W_{lost} = T_{surr} *S

where ;

T_{surr} is the temperature of the surrounding. = 20°C = (20+273.15)K =  293.15 K

From above the change in entropy is:

\delta \  S = C_p \  In (\frac{T+ \delta \ T }{T}) *  \beta V \delta P

\delta \  S = 4.19*  \  In (\frac{288.15+0.093 }{288.15}) -  1.5*10^{-4} * 1.001 (5-1)* (\frac{1}{9.87})

\delta \  S =1.408*10^{-3} \ J/gm.K

W_{lost} = T_{surr} *S

W_{lost} = 293.15* 1.408*10^{-3} \ J/gm.K

W_{lost} = 0.413 \  kJ/kg

Thus, the lost work per kilogram of water for this everyday household happening = 0.413 kJ/kg

6 0
4 years ago
How are radio waves carried?
bagirrra123 [75]

Answer:

c from transmitter to a receiver

6 0
4 years ago
Read 2 more answers
Other questions:
  • 3. A competency-based training program is
    13·1 answer
  • : A pneumatic "cannon" is a device that launches a low mass projectile from a cylindrical tube using pressurized air stored upst
    6·1 answer
  • The article "Some Parameters of the Population Biology of Spotted Flounder (Ciutharus linguatula Linnaeus, 1758) in Edremit Bay
    9·1 answer
  • A primary incentive for entrepreneurs is
    5·1 answer
  • Is an ideal way for a high school student to see what an engineer does on a typical day but does not provide a hands-on experien
    9·2 answers
  • Plz watch our you tube channel called addie nahoe. I got 8 subscribers. I need 10. Plz like and hit that nocation bell. Plz!!!!
    12·1 answer
  • A well-insulated heat exchanger has one line with 2 kg/s of air at 125 kPa and 1000 K entering, and leaving at 100 kPa and 400 K
    7·1 answer
  • 5.<br> Which of the following is considered ideal conditions?
    14·1 answer
  • 1. What are hand tools ? *
    6·1 answer
  • If it is safe to do so you should shut off your engine if it’s going to be idling for longer than?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!