Finding The Factors of a Number Using Computer Science by @mraspinall #edtech

Finding The Factors of a Number Using Computer Science by @mraspinall #edtech

Factors and multiples. A very important mathematics concept. Understanding how to determine factors and multiples is a unique skill. There are divisibility rules for numbers ending in 0, 5, 2 etc. There is the sum of the digits rule.

This week we took these practices to the next step. When it was evident we (as a class) had a good understanding of how to find the factors of a number, we created an algorithm for it.


We determined that you must divide the original composite number by all numbers lower than 50% of the original number, beginning with 2. 1 is always a factor and after 50% we begin to repeat. We immediately decided a loop would be most efficient here.

This lesson also taught us about MOD (returning the remainder of the quotient of two numbers) – a handy little function in the computer science world.

Once our algorithm was complete, it was time to implement it into practice.


What I love about this process is not only are we learning how to find factors – we are learning about variables, arrays, lists, procedures, algorithms and problem solving. We are learning what it means to increment a variable.

After a few test runs, we noticed bugs. Our variables and lists were not resetting on each run because we forget to initialize our variables to ‘null’ at the beginning of the program.

By the end of the lesson we had compiled enough code to find all the factors of two composite numbers. Each was displayed in a nice list making it incredibly straight forward to find the GCF manually.

Our next step will be to code our app to compare each element in both lists and determine the greatest number common to both, or the GCF.


We had a brief discussion about multiples and decided we had to cap the limit. IE: our app would find the multiples of a number up to 10,000 or something like that.

We may also find all the factors of the factors (IE: Prime Factorization) in order to determine the GCF and LCM – but that’s what student choice is about. I just want to see them build an app to find the GCF and LCM – I’m not picky about which strategy or process they choose.

What is pretty neat about this lesson – they can now use their own app to solve the old Nelson textbook problems in limited time.

This is just another example of coding for a purpose. We took the (somewhat) trivial task of finding factors and turned it into a handy little tool.

I love math class. I especially love CS Math class! I equate coding in the future to changing a car tire today. Just one of those skills everyone is expected to have.

Here is the finished product:

Happy Wednesday folks!

(Visited 1,019 times, 1 visits today)

Leave a Reply

Email *