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
Plssssssssssssss Alexi is writing a program which prompts users to enter their age. Which function should she use?
aleksandr82 [10.1K]

Answer:

int()

Explanation:

float() is using decimals, so that can't be it, like float(input( "how much does this cost?"))

print() is used to print something, not a user asking, like print("hello")

string() means like a whole, like string( I am good)

By elimination, int() is correct.

Hope this helps!

7 0
3 years ago
True or False: The differential lock in an AWD-equipped vehicle can be used at any time.
Bingel [31]

the answer would be false

7 0
3 years ago
Read 2 more answers
A battery is connected to a resistor. Increasing the resistance of the resistor will __________. A battery is connected to a res
belka [17]

Answer: the increase in the external resistor will affect and decrease the current in the circuit.

Explanation: A battery has it own internal resistance, r, and given an external resistor of resistance, R, the equation of typical of Ohm's law giving the flow of current is

E = IR + Ir = I(R + r)........(1)

Where IR is the potential difference flowing in the external circuit and Or is the lost voltage due to internal resistance of battery. From (1)

I = E/(R + r)

As R increases, and E, r remain constant, the value (R + r) increases, hence the value of current, I, in the external circuit decreases.

8 0
3 years ago
The typical area of a commercial airplane's passenger window is 80.0 in^2 . At an altitude of 3.00 × 104 ft above the sea level,
nikdorinn [45]

Answer:

The force over the plane windows are 764 lbf in the EE unit system and 3398 N in the international unit system.

Explanation:

The net force over the window is calculated by multiplying the difference in pressure by the area of the window:

F = Δp*A

The pressure inside the plane is around 1 atm, hence the difference in pressure is:

Δp = 1atm - 0.35 atm = 0.65 atm

Expressing in the EE unit system:

Δp = 0.65 atm * 14.69 lbf/in^2 = 9.55 lbf/in^2

Replacing in the force:

F = 9.55 lbf/in^2 * 80 in^2  = 764 lbf

For the international unit system, we re-calculate the window's area and the difference in pressure:

A = 80 in^2 * (0.0254 m/in)^2 = 0.0516 m^2

Δp =  0.65 atm * 101325 Pa  = 65861 Pa  = 65861 N/m^2

Replacing in the force:

F = 65861 N/m^2  *0.0516 m^2  = 3398 N

3 0
3 years ago
Thermodynamics 3-Hacmi 2 m3 olan kapalı bir kap 200 kPa basınçta 4 kg doymuş sıvı ve doymuş buhar karışımı su bulundurmaktadır.
Rufina [12.5K]
I want say the best answer is C a sister-in-law Tran
7 0
3 years ago
Other questions:
  • 11) (10 points) A large valve is to be used to control water supply in large conduits. Model tests are to be done to determine h
    12·1 answer
  • Sed is a multipurpose tool that combines the work of several filters. sed performs noninteractive operations on a data stream. s
    12·1 answer
  • Explain three (3) modes of heat transfer in air conditioning system.
    7·1 answer
  • What is a shearing stress? Is there a force resulting from two solids in contact to which is it similar?
    6·1 answer
  • Show that -40 F is approximately equal to -40 C.
    12·1 answer
  • ______________ help protect the lower legs and feet from heat hazards like molten metal and welding sparks. A) Safety shoesB) Le
    7·1 answer
  • Pleaseeee help me with this!!
    10·1 answer
  • The formation of faults in Earth's crust is an effect. What causes faults to form in the crust? Global Positioning System sensor
    9·1 answer
  • Which option identifies why Ethan’s skills are valuable to his team in the following scenario?
    8·1 answer
  • In an ungrounded electrical systems with conductors installed in grounded metal raceways and enclosures, what is the voltage fro
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!