Escolar Documentos
Profissional Documentos
Cultura Documentos
repetition control
structures(DOWHILEENDDO, REPEAT
UNTIL, DOTOENDDO)
repetition construct
Perspectives
From Logical (Theory) Perspectives
we implement in programming
Definite Loop counter-controlled loop
I.
II.
Repetition in C
Programming
Definite
Indefinite
for loop
for loop
while loop
while loop
do-while loop
do-while loop
Repetition in C
Programming
Counted Loop
Definite
for loop
Leading Decision
Loop
Indefinite
Trailing Decision
Loopfor loop
while loop
while loop
do-while loop
do-while loop
Repetition - Theory
There are three different ways that a set of
Logical
Implementation
(Theory) (Programming)
Repetition - Theory
DOWHILE ENDDO
REPEAT UNTIL
do-while loop
C. Counted loop
DO TO ENDDO
the loop
data
This sentinel is a special record or value placed at
REPEAT
statement
Display Hello
statement
Display Welcome
.
.
UNTIL condition is true
UNTIL exit is 1
condition is false
Second, the statements within a REPEATUNTIL
statement block
1. Initialize the loop_index to the required
initial_value
2. Increment the loop_index by 1 for each pass
through the loop
3. Test the value of loop_index at the beginning of
each loop to ensure that it is within the stated
range of values
4. Terminate the loop when the loop_index has
exceeded the specified final_value
Learning outcomes
Develop algorithms that use the
repetition control
structures(DOWHILEENDDO, REPEAT
UNTIL, DOTOENDDO)
repetition construct
Questions
Print out all integers from 5 down to -5 by using
repetition
Expected Output:
5 4 3 2 1 0 -1 2 3 4 5
Questions
In mathematics, the factorial of a non-negative
integer n, denoted by n!, is the product of all
positive integers less than or equal to n. For
example,
5! 1 2 3 4 5 120
where n! represents n factorial. The notation n!
was introduced by Christian Kramp in 1808. Write
a C program to demonstrate how a program is
able to calculate the value of a n factorial if n is
provided by user.
(11 marks)
Questions
Create a program to calculate how long does it
take for a student to get RM10,000 assuming
that student deposit RM5,000 into a Bank with
yearly interest 2%.
Questions
Create a program to get a series of integers determined
by user, and display the largest number, smallest
number, and average.
Expected Output:
Total Integers: 2
Insert Integer 1: 5
Insert Integer 2: 6
Smallest Number: 5
Largest Number: 6
Average: 5.5