0% found this document useful (0 votes)
11 views9 pages

Solution Trace Table Assignment

The document contains assignments related to trace tables, algorithms, and pseudo-code for various programming tasks. It includes trace tables for checking divisibility by 7, printing squares of numbers, calculating kinetic energy, and calculating the factorial of a number. Each section provides detailed pseudo-code and corresponding trace tables for specific input values.

Uploaded by

aasiaidrees42
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views9 pages

Solution Trace Table Assignment

The document contains assignments related to trace tables, algorithms, and pseudo-code for various programming tasks. It includes trace tables for checking divisibility by 7, printing squares of numbers, calculating kinetic energy, and calculating the factorial of a number. Each section provides detailed pseudo-code and corresponding trace tables for specific input values.

Uploaded by

aasiaidrees42
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment

Trace Table, Algorithm, Pseudo-code

FG. Degree College Attock Cantt.


Q:1 Make Trace Table for following pseudo-code

Pseudo-code
Step1: Start
Step2: Input n
Step 3: r = n mod 7
Step 4: If r = 0
Step 5: Print “Number is divisible by 7”
Step 6: Else
Step 7: Print “Number is not divisible by 7”
Ste p 8: Stop

Make two trace table for this pseudo-code, Assume:


n = 21 for first trace table
n= 19 for second trace table
Solution: When n = 21

Trace Table
Line No n r is r = 0 Output
Step 2 21 - - -
Step 3 21 0 - -
Step 4 21 0 T -
Step 5 21 0 - Number is Divisible by 7
Solution: When n = 19

Trace Table
Line No n r is r = 0 Output
Step 2 19 - - -
Step 3 19 5 - -
Step 4 19 5 F -
Step 7 19 5 - Number is not Divisible by 7
Q:2 Make Trace Table for following pseudo-code

Pseudo-code
Step1: Start
Step2: i=1
Step 3: While i<10
Step 4: Print i x i
Step 5: i=i+2
Step 6: End While
Step 7: Stop
Trace Table
Line No i i <= 10 Output
Step 2 1 - -
Step 3 1 T -
Step 4 1 - 1
Step 5 3 - -
Step 3 3 T -
Step 4 3 - 9
Step 5 5 - -
Step 3 5 T -
Step 4 5 - 25
Step 5 7 - -
Step 3 7 T -
Step 4 7 - 49
Step 5 9 - -
Step 3 9 T -
Step 4 9 - 81
Step 5 11 - -
Step 3 11 F -
Q 3: Write pseudo-code that calculates kinetic energy using
following formula:

Kinetic Energy = 1/2mv2

Pseudo-code:

Step 1 Start
Step 2 Input m
Step 3 Input v
Step 4 Calculate ke = ½ × m × v × v
Step 5 Print ke
Step 6 End
Q 4: Write pseudo-code for calculating factorial of a number and
make its trace table.

Pseudo-code:

Step 1 Start
Step 2 Input n
Step 3 fact = 1
Step 4: i=1
Step 5: while i <= n
Step 6: fact = fact × i
Step 7: i = i+1
Step 7: End While
Step 8: Print fact
Step 9: End
Line No n fact i i<=n Output
Step 2 5 - - -
Step 3 5 1 - -
Step 4 5 1 1 - -
Step 5 5 1 1 T -
Step 6 5 1 1 - -
Step 7 5 1 2 - -
Step 5 5 1 2 T -
Step 6 5 2 2 - -
Step 7 5 2 3 - -
Step 5 5 2 3 T -
Step 6 5 6 3 - -
Step 7 5 6 4 - -
Step 5 5 6 4 T- -
Step 6 5 24 4 - -
Step 7 5 24 5 - -
Step 5 5 24 5 T -
Step 6 5 120 5 - -
Step 7 5 120 6 - -
Step 5 5 120 6 F -
Step 8 5 120 6 - 120

You might also like