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
What classes do you have to take in college for be a system software engineer
nata0808 [166]
Engineering, maths and computer courses and more depending on your deficiencies
4 0
3 years ago
Ayuda!<br> es para mañana
ExtremeBDS [4]
No se ve la foto :( puedes a ser la pregunta otra ves?
8 0
3 years ago
Steam enters an adiabatic turbine at 800 psia and9008F and leaves at a pressure of 40 psia. Determine themaximum amount of work
Naily [24]

Answer:

w_{out}=319.1\frac{BTU}{lbm}

Explanation:

Hello,

In this case, for the inlet stream, from the steam table, the specific enthalpy and entropy are:

h_1=1456.0\frac{BTU}{lbm} \ \ \ s_1=1.6413\frac{BTU}{lbm*R}

Next, for the liquid-vapor mixture at the outlet stream we need to compute its quality by taking into account that since the turbine is adiabatic, the entropy remains the same:

s_2=s_1

Thus, the liquid and liquid-vapor entropies are included to compute the quality:

x_2=\frac{s_2-s_f}{s_{fg}}=\frac{1.6313-0.39213}{1.28448}=0.965

Next, we compute the outlet enthalpy by considering the liquid and liquid-vapor enthalpies:

h_2=h_f+x_2h_f_g=236.14+0.965*933.69=1136.9\frac{BTU}{lbm}

Then, by using the first law of thermodynamics, the maximum specific work is computed via:

h_1=w_{out}+h_2\\\\w_{out}=h_1-h_2=1456.0\frac{BTU}{lbm}-1136.9\frac{BTU}{lbm}\\\\w_{out}=319.1\frac{BTU}{lbm}

Best regards.

3 0
3 years ago
A cylindrical rod of a metal alloy is stressed elastically in tension. The original diameter was 11 mm and a force of 55 kN was
andrey2020 [161]

Answer:

10.984mm

Explanation:

by elastic modulus

stress=modulus of elasticity*strain

stress=loading/area                          area" cross-section"

11mm=0.011m

area=π(d/2)^2=π(0.011/2)^2=9.503*10^-5 square meter

stress=55000/(9.503*10^-5)=578.745 MPa

convert MPa and GPa to pascal.

strain=stress/modulus=(578.745*10^6)/(125*10^9)=0.00463............axial strain

v=Poisson  ratio

lateral strain=(-v)*axial strain= -0.31*0.00463

lateral strain= -1.4353*10^-3=change in diameter/ original diameter

change in diameter=(-1.4353*10^-3)*0.011= -1.57883*10^-5 m

negative indicates decrease in diameter.

decrease in dia.=0.01578mm

new diameter=11-0.01578= 10.984mm

3 0
3 years ago
Why different types of <br> engines used gas turbine give reasons
Romashka [77]

Answer:

Four types of gas turbine engines are used to propel and power aircraft. They are the turbojet, turbofan, turboprop, and turboshaft.

6 0
3 years ago
Read 2 more answers
Other questions:
  • Suppose a consumer advocacy group would like to conduct a survey to find the proportion p of consumers who bought the newest gen
    14·1 answer
  • What engine does the Lexus is300 have?
    5·1 answer
  • Metallic nickel crystallizes in a face-centered cubic lattice. If the edge length of the unit cell is found to be 352 pm, what i
    11·1 answer
  • 50. You are not permitted to work on any equipment or machinery at any time if the
    13·1 answer
  • In a creep test, increasing the temperature will (choose the best answer) A. increase the instantaneous initial deformation B. i
    5·1 answer
  • : THE NEXT BIG THING In this lesson, you learned about two revolutionary new ideas that have engineers hard at work. There are m
    13·1 answer
  • What are the steps to execute an instruction by cpu?What is the function of DMA controller.
    13·1 answer
  • There are some sections of the SDS that are not mandatory.
    11·1 answer
  • How to calculate maximum shear stress in the cross-section of a beam if the neutral axis is not on the thinnest part of the cros
    7·1 answer
  • How does accenture generate value for clients through agile and devops?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!