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
Consider a resistor made of pure silicon with a cross-sectional area pf 0.5 μm2, and a length of 50 μm. What is the resistance o
lukranit [14]

Answer: 24 pA

Explanation:

As pure silicon is a semiconductor, the resistivity value is strongly dependent of temperature, as the main responsible for conductivity, the number of charge carriers (both electrons and holes) does.

Based on these considerations, we found that at room temperature, pure silicon resistivity can be approximated as 2.1. 10⁵  Ω  cm.

The resistance R of a given resistor, is expressed by the following formula:

R = ρ L / A

Replacing by the values for resistivity, L and A, we have

R = 2.1. 10⁵ Ω  cm. (10⁴ μm/cm). 50 μm/ 0.5 μm2

R = 2.1. 10¹¹ Ω

Assuming that we can apply Ohm´s Law, the current that would pass through this resistor for an applied voltage of 5 V, is as follows:

I = V/R = 5 V / 2.1.10¹¹ Ω = 2.38. 10⁻¹¹ A= 24 pA

7 0
3 years ago
What is (10 to the power of three) times (3 to the power of 10)? will give brainliest
VLD [36.1K]

59,049,000 is the answer.

7 0
3 years ago
Create a series of eight successive displacements that would program a robot to move in an octagonal path that is as close as yo
Komok [63]

Answer:

bts biot bts biot jungkukkk

jungkukkkbiot

Explanation:

bts biot bts biot jungkukkk

jungkukkkbiot

5 0
3 years ago
Who can use NIST resources?
sukhopar [10]

Answer:

Federal agencies

Explanation:

NIST (National Institute of Standards and Technology) also called between 1901 and 1988 National Bureau of Standards (NBS), it is an agency of the Technology Administration of the United States Department of Commerce. The mission of this institute is to promote innovation and industrial competition in the United States through advances in metrology, standards and technology in ways that improve economic stability and quality of life.

As part of this mission, NIST scientists and engineers continually refine the science of measurement (metrology) by creating precise engineering and manufacturing required for most current technological advances. They are also directly involved in the development and testing of standards made by the private sector and government agencies. The NIST was originally called the National Bureau of Standards (NBS), a name it had from 1901 to 1988. The progress and technological innovation of the United States depends on the abilities of the NIST, especially if we talk about four areas: biotechnology , nanotechnology, information technologies and advanced manufacturing.

7 0
3 years ago
The correct area in sq. Inches and sq. Feet is: Select one: a. 966.76 sq. Inches and 8.056 sq. Feet b. 96.676 sq. Inches and 8.0
kogti [31]

Answer:

c. 96.676 sq. Inches and 0.671 sq. Feet

Explanation:

From the list of the given option, we are told to chose the correct area in sq. inches that correspond to sq. Feet.

If we recall from the knowledge of our conversion  table that,

1 sq feet = 144 sq inches

Then, let's confirm if the option were true.

a.  966.76 sq. Inches and 8.056 sq. Feet

Assuming

if 1 sq feet = 8.056

in sq inches, we have ( 8.056 × 144 ) sq inches

= 1160.064 sq. inches

So, 1160.064 sq. inches is equal to 8.056 sq. Feet. Then option 1 is wrong

b. 96.676 sq. Inches and 8.056 sq. Feet

if 1 sq feet = 8.056

in sq inches, we have ( 8.056 × 144 ) sq inches

= 1160.064 sq. inches

So, 1160.064 sq. inches is equal to 8.056 sq. Feet. Then option 2 is wrong/

c. 96.676 sq. Inches and 0.671 sq. Feet

if 1 sq feet = 0.671

in sq inches, we have ( 0.671 × 144 ) sq inches

=  96.624 sq. Inches which is closely equal to 96.676 sq. Inches

Therefore, this is the correct answer as it proves that 96.676 sq. Inches = 0.671 sq. Feet

8 0
3 years ago
Other questions:
  • Design a half-wave recti er which provides a peak voltage of 15 V, and anaverage voltage of 3.8 V when driven by a 120 V (rms) a
    10·1 answer
  • A piston–cylinder device contains a mixture of 0.5 kg of H2 and 1.2 kg of N2 at 100 kPa and 300 K. Heat is now transferred to th
    8·1 answer
  • At a certain location, wind is blowing steadily at 10 m/s. Determine the mechanical energy of air per unit mass and the power ge
    5·1 answer
  • If the resistance reading on a DMM'S meter face is to 22.5 ohms in the range selector switch is set to R X 100 range, what is th
    5·1 answer
  • What are the four basic parts of process plan
    11·1 answer
  • Why dues brainy exist as a learning platform when it is just full of answers and you won't learn anything?
    8·1 answer
  • You are investigating surface hardening in iron using nitrogen gas. Two 5 mm thick slabs of iron are separately exposed to nitro
    10·1 answer
  • Sinks must be used for the correct intended purpose to prevent
    7·1 answer
  • Can someone please help me with this <br>I've an exams tomorrow ​
    7·1 answer
  • How can I draw this image in 2D form
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!