# Pseudo Code

Pseudo code is a sort of cross between English and computer
code.

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
quadratic equation

ax^{2}
+ bx + c = 0

using the quadratic formula.

- Let d = b
^{2} - 4ac
- If d < 0 print 'no real solutions' and go to step 5
- Let X
_{1} = (-b + SQRT(d))/(2a)
- Let X
_{2} = (-b - SQRT(d))/(2a)
- Print X
_{1} and X_{2}
- Stop

Here is the Russian peasants' algorithm for long multiplication

#### Algorithm

- Write the two numbers to be multiplied next to each other.
- Double the left number and write the result underneath the
left number.

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
is even.

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.

#### Example

To find 34 x 51

34 51

68 25

136 12

272 6

544 3

1088 1

Crossing out the rows where the right hand number is even would leave:

34 51

68 25

-----------

-----------

544 3

1088 1

Adding the remaining numbers in the left hand column gives 1734 which
is the answer to 34 x 51