Dry Run 3:
Input:
a = 0
b = 2
c = 1
Expected output:
Not a quadratic equation.
Process:
Is a= =0 ?
Is 0 = = 0 → true
Observed Output:
Not a quadratic equation.
NOTE
In all of the preceding dry runs, the expected output equals the observed output.
Example
3: Write an algorithm to read x, y, and z as the three sides of a triangle and to check
the type of triangle formed; then validate your algorithm by giving it dry runs.
Solution 3:
The algorithm to check for the triangle type is as follows:
Triangle_type (x, y, z)
Step 1:
Input three sides of triangle: x, y, z.
Step 2:
check if (x + y > z) && (y + z > x) && (x + z >y)
Step 3:
then do if (x= y && y = z)
Step 4:
then Print: ‘Equilateral triangle’ and go to step 17.
Step 5:
else
Step 6:
do if (x = y && y! =z) || (x = z && z!=y) || (y=z &&x!=z)
Step 7:
then do if (x = sqrt( z
2
/2) || (x = sqrt(y
2
/2) || (y = sqrt(x
2
/2))
Step 8:
Print: ‘Right Angled Isosceles Triangle’ and go to step 17.
Do'stlaringiz bilan baham: