Lesson 8: Dry Running

Performing a Dry Run Test

  • Choose an algorithm or program to test.
  • Manually execute it step by step, tracing its execution.
  • Record the execution steps and outcomes in a trace table.
  • Identify any defects or errors.

Example 1: Find the Maximum of Two Numbers

Algorithm: Read two numbers a and b. If a > b, max = a. Else, max = b. Print max.

Dry run (a = 5, b = 3): Since a > b, max = 5. Output: 5.

Example 2: Sum of All Even Numbers From 1 to n

Algorithm: Initialize sum = 0. For i = 1 to n, if i is even, sum = sum + i. Print sum.

Dry run (n = 5): i=1 (odd, skip), i=2 (even, sum=2), i=3 (odd, skip), i=4 (even, sum=6), i=5 (odd, skip). Output: 6.

Leave a comment

Your email address will not be published. Required fields are marked *

sponsors Ads