0% found this document useful (0 votes)
49 views

Computer Assignment

The document provides instructions for Assignment 1 Topic 4, requiring the student to answer Exercises 9 through 12 on technical programming approaches by submitting pdf files. The exercises include pseudocode, flowcharts, and trace tables for programs that perform logical comparisons on numbers and calculate sums and differences, as well as programs using while and do-while loops.

Uploaded by

Poh Yong Wei
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Computer Assignment

The document provides instructions for Assignment 1 Topic 4, requiring the student to answer Exercises 9 through 12 on technical programming approaches by submitting pdf files. The exercises include pseudocode, flowcharts, and trace tables for programs that perform logical comparisons on numbers and calculate sums and differences, as well as programs using while and do-while loops.

Uploaded by

Poh Yong Wei
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Assignment 1-Topic 4.

1. Please answer Exercise 9, 10, 11, and 12 in Topic 04 Technical Approaches to


Programming.

2. Submit all answers in pdf format.

Exercise 9:
Pseudocode:
1. Start
2. Read num1, num2
3. If num1 > num2
Calculate difference = num1 – num2
Display number and difference
4. Else
Calculate sum = num1 + num2
Display number and sum
5. End if
6. End
Flowchart:

Start

Read num1, num2

num1 > num2 True

difference = num1 – num2


False

sum = num1 + num2

Display number and different

Display number and sum

End
Trace table:

Num1 Num2 Condition Output


40 50 num1 < num2 40+50=90
70 30 num1 > num2 70-30=40
Exercise 10:

Pseudocode:

1. Start
2. Read num1, num2
3. If num1 > num2 && num1 > 50
Calculate sum = num1 + num2
Display sum
4. Else
Calculate difference = num1 – num2
Display difference
5. End if
6. End
Flowchart:

Start

Read num1, num2

num1 > num2 True


&& num1 > 50

False

sum = num1 + num2

difference = num1 – num2

Display difference Display sum

End
Trace table:

Num1 Num2 Condition Output


52 30 num1 > num2 && num1 > 50 52+30=82
Exercise 11:

Pseudocode:

1. Start
2. Set sum = 0, count = 0
3. While (count < 15)
Get number
Sum = sum + count
Counter = counter + 1
4. End while
Average = sum / number of counter
5. Display average
6. End
Flowchart:

Start

sum = 0, count = 0

Count <=15 False

True

Average = sum / number of


counter
Read number

Display average
Sum = sum + counter

Counter = counter + 1 End


Exercise 12:

Pseudocode:

Pre-test loop:

1. Start
2. Set number = 0, counter = 1
3. While (count <= 50)
3.1 Number = number + 2
3.2 Counter = counter + 1
3.3 Print number
4. End while
5. End
Flowchart:

Start

Number = 0, counter = 1

count <= 50 False


End

True

Number = number + 2

Counter = counter + 1

Printer number
Post - test loop:

1. Start
2. Set number = 0, counter = 1
3. Do
3.1 Number = number + 2
3.2 Counter = counter + 1
3.3 Print number
4. While (counter <=50)
5. End
Flowchart:

Start

number = 0, counter = 1

Number = number + 2

Counter = counter + 1

Printer number

True Count<=50

False

End

You might also like