C Programming

SEQUENCE STATEMENTS THEORY QUESTIONS

1

(a)

Define the term sequence statement

(b)

Write down the line of code to display the message "Programming is fun!" on the screen

(c)

Write down and explain briefly the function for getting input from the use

2

A programmer is tasked with writing code to calculate the kinetic energy of a body in C.

He decided to name the variables to store the mass and velocity as mass and velocity respectively.

Use the above information to answer the following questions:

(a)

Write the code to instruct the user to enter the mass.

(b)

Write the code to get the mass from the user.

(c)

Write the code to instruct the user to enter the velocity.

(d)

Write the code to get the velocity from the user.

(e)

If he decides not to store the calculated kinetic energy in a variable, write the code to calculate and display it directly.

For instance if the mass entered is 10 and the velocity entered is 5, the kinetic energy would be 125.

Your display should be:

The kinetic energy of a body of mass 10 kg and velocity 5 m/s is 125 J.

Note: The kinetic energy is calculated using the formula KE = 1 2 mv2, where KE is the kinetic energy, m is the mass and v is the velocity.