Вы находитесь на странице: 1из 4

FACULTY OF SCIENCE AND TECHNOLOGY

SEMESTER 1163

CBCP2101

COMPUTER PROGRAMMING I

MATRICULATION NO : 901107025629001

IDENTITY CARD NO. : 901107025629

TELEPHONE NO. : 011 1075 1814

E-MAIL : ikhwan_ishak@oum.edu.my

LEARNING CENTRE : KEDAH LEARNING CENTRE, ALOR SETAR


Programming technique: Counter controlled loop – Loop with increasing counter control

Input:

1) Year, y ; y >= 1 ; y <= 7

2) Initial value, i = 28000

3) Depreciation value per year = 4000

Output:

1) End of year value, end_value ← i – 4000

2) Accumulated depreciation, accumulated_depreciation ← 4000*y

Pseudocode:

1.0 Start
2.0 Set y = 1 and i = 28000
3.0 For (y = 1 ; (y >= 1 and y <= 7) ; i decrement 4000) start_for
3.1 end_value ← i – 4000
3.2 accumulated_depreciation ← 4000*y
3.3 End_for
4.0 Print end_value and accumulated_depreciation
5.0 End
Tracing table:

y y >= 1 ; y <= end_value ← i – 4000 accumulate_depreciation ← 4000*y


7
1 True 24000 ← (28000 – 4000) 4000 ← (4000*1)
2 True 20000 ← (24000 – 4000) 8000 ← (4000*2)
3 True 16000 ← (20000 – 4000) 12000 ← (4000*3)
4 True 12000 ← (16000 – 4000) 16000 ← (4000*4)
5 True 8000 ← (12000 – 4000) 20000 ← (4000*5)
6 True 4000 ← (8000 – 4000) 24000 ← (4000*6)
7 True 0 ← (4000 – 4000) 28000 ← (4000*7)
8 False 0 28000
Flowchart:
Start

y=1

i = 28000

depreciation = 4000

FALSE
y >= 1 AND y <= 7

TRUE

end_value ← i – 4000

accumulated_depreciation ← 4000*y

Print end_value

Print accumulated_depreciation

End

Вам также может понравиться