Pseudo code is a sort of cross between English and computer
It allows for easy transfer of the algorithm to a compter language.
Zeller's algorithm would be written in pseudo code like this:
- Let D be Day number.
Let M be Month number.
Let Y be Year number.
- If M < 3 then M := M + 12 and Y := Y - 1
- Let A = INT (Y / 100)
Let B = Y - (100 x A)
- Let S = INT (2.6 x M - 5.39) + INT (B / 4) + INT (A / 4)
+ D + B - (2 x A)
- Let Day = S - (7 x INT (S / 7))
This algorithm can be used to find the real roots of the
+ bx + c = 0
using the quadratic formula.
- Let d = b2 - 4ac
- If d < 0 print 'no real solutions' and go to step 5
- Let X1 = (-b + SQRT(d))/(2a)
- Let X2 = (-b - SQRT(d))/(2a)
- Print X1 and X2
Here is the Russian peasants' algorithm for long multiplication
- Write the two numbers to be multiplied next to each other.
- Double the left number and write the result underneath the
Halve the right number, ignore any remainder and write the result
underneath the right number.
- Repeat step 2 until the right number is 1.
- Delete those rows where the number in the right hand column
Add the remaining numbers in the left column.
This is the result of multiplying the two original numbers.
Write the Russian peasants' algorithm in pseudo code.
Click here for one possible answer.
To find 34 x 51
Crossing out the rows where the right hand number is even would leave:
Adding the remaining numbers in the left hand column gives 1734 which
is the answer to 34 x 51