Highest Common Factors – Euclid's algorithm

Step 5 – three numbers

Once you have the basic algorithm it can be extended to three (or more) numbers easily.

Here's a wy of extending it to three numbers:

  1. Save your program with a different name so that you don't lose your working program!
  2. Add to the first part of the program to collect three numbers from the user
  3. Use the same WHILE loop for number1 and number2 – but don't print the HCF yet
  4. Then copy the loop and run it again for number2 and number3

    It doesn't matter which f number1 or number2 that you use here. By thispoint they are the same number anyway

  5. Then report the HCF at the end. You can use either of the numbers you ran through the last loop as they're the same by this point

That should work. Now there's an extra challenge...

Prime Challenge

Add to your program to report to the user if one of the numbers they entered might be a prime number. How can you tell from the HCF?

You can't tell for sure (think about the HCF of 4 and 9...). What else could you do to find out for sure? Is there a way to solve this problem, perhaps using prime factorisation?

You'll need to do some research on this. And perhaps talk to me.