University of Technology, Jamaica
School of Computing & Information Technology
Programming II – Tutorial Week 2
1. Fill in the blanks in each of the following.
a) All programs can be written in terms of three types of control statements:
____________________________ , _______________________________ and
______________________________.
b) The ________________________ selection statement is used to execute one action when a condition
is true and another action when that condition is false.
c) Several statements grouped together in braces ( { and } ) are called a(n)
_________________________.
d) The ____________________ repetition statement specifies that a statement or group of statements is
to be executed repeatedly while some condition remains true.
e) Repetition of a set of instructions a specific number of times is called_________________________
repetition.
f) When it is not known in advance how many times a set of statements will be repeated, a(n)
________________________ value can be used to terminate the repetition.
g) A synonym for procedure is ______________________________.
h) A variable that accumulates the sum of several numbers is a(n) _________________________ .
i) Setting certain variables to specific values at the beginning of a program is called
______________________.
j) A special value used to indicate “end of data entry” is called a(n) _____________________, a(n)
______________________, a(n) _____________________ or a(n) _________________ value.
k) A(n) ____________________________________ is a graphical representation of an algorithm
2. Write four different C statements that each add 1 to integer variable x.
3. Write a single C statement to accomplish each of the following:
a) Assign the sum of x and y to z and increment the value of x by 1 after the calculation.
b) Multiply the variable product by 2 using the *= operator.
c) Multiply the variable product by 2 using the = and * operators.
d) Test if the value of the variable count is greater than 10. If it is, print “Count is greater than 10.”
e) Decrement the variable x by 1, then subtract it from the variable total.
f) Add the variable x to the variable total, then decrement x by 1.
g) Calculate the remainder after q is divided by divisor and assign the result to q. Write this
statement two different ways.
h) Print the value 123.4567 with 2 digits of precision. What value is printed?
i) Print the floating-point value 3.14159 with three digits to the right of the decimal point. What
value is printed?
4. Write a C statement to accomplish each of the following tasks.
a) Define variables sum and x to be of type int.
b) Initialize variable x to 1.
c) Initialize variable sum to 0.
d) Add variable x to variable sum and assign the result to variable sum.
e) Print "The sum is: " followed by the value of variable sum.
5. Complete the following exercises from the C How To Program text.
3.17, 3.18, 3.19, 3.20, 3.21 and 3.22