Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

RESULTS

Part A : Increment and Decrement Operators


LISTING 3-1

i) The output by line:


8 is a = 4
9 is b = 4
12 is a = 3
13 is b = 3
15 is 5
15 is 6
17 is 6
19 is 5
20 is 5
21 is 6
Part B : t
LISTING 3-2
1.

i)

ii) The output display for the last printf statement are the class average which is 6.

2.
Part C : for Repetition Statement
LISTING 3-3
Part D : Break and Continue Statement
LISTING 3-4
LISTING 3-5
EXERCISE 1
i)

ii)
EXERCISE 2
i)

ii)
EXERCISE 3
INPUT

OUTPUT
EXERCISE 4
INPUT

OUTPUT
EXERCISE 5
i)

ii)
DISCUSSION
In this Lab Report, it discussed on repetitive statement, there are bunch of
repetitive statement. The first one would be the increment, decrement and
assignment operators. Another one would be the while repetition statement.
Furthermore, using for and do is also one of the while statements.
In Part A, it discussed about the “increment and decrement operators” using +
+ as increment operator and – decrement operator. If increment or decrement
operators are placed before a variable (prefixed), they are referred to as the
preincrement or predecrement operators. For example as shown in the result
of Listing 3-1, the variables that is used are a, b, and c. To show the increment
statement, “printf” is used to display the output and using “++” operator to
show the increment.
In Part B, it discussed about the “while repetition statement” using ‘while’
statement as shown in the result in Listing 3-2. while statement are used when a
block of statements have to be repeated, but the number of repetitions is not a
fixed amount. This means that a while statement might repeat two times when
a program is run and repeat a different number of times the next time that same
program is run. For example, as shown in the Listing 3-2, first counter is
declared and initialized as 0. Then while statement is executed for the first time.
As shown on the input, the programme is about inputting mark for 5 times as
the while statement is 5 times. Furthermore, the class average is calculated by
dividing the total mark by 5.
In Part C, it discussed about the “for statement”. The for statement lets you
repeat a statement or compound statement a specified number of times. The
body of a for statement is executed zero or more times until an optional
condition became false. For example, as shown in the Listing 3-3, for statement
is used to repeat the variable i that execute number 2 to 20, in a plus 2. For
statement is also use after sum is initialized and also squares.

In Part D, in this part, it discussed about the break and continue statement.
The Break Statement ends the loop immediately when it is encountered. For
example in the Listing 3-4, the break statement is used with if statement inside
the loop which is “while statement”. The continue statement skips the current
iteration of the loop and continues with the next iteration. In this case, continue
is used with the if statement. For example in the Listing 3-4, the continue
statement is used when the y variable is increasing.
CONCLUSION
In conclusion, student is able to understand and use the increment, decrement
and assignment operators, Furthermore, student also able to use the while
repetition statement to execute statements in a program repeatedly. In addition,
student able to use the for and do… while repetition statements to execute
statements in a program repeatedly. Lastly, student able to use the break and
continue statement to alter the flow out of control.

You might also like