usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< PreviousNext >>

Code for Listing Factors of Numbers in Visual Basic (VB.Net)



What are Factors

Factors are the complete set of integers that will divide a particular numbers without remainder.
Take 36 as an example, it's complete set are:

1, 2, 3, 4, 6, 9, 12, 18, and 36.

Other than prime numbers, every other number has at least one factor - not considering 1 as factor.
Where there is just one factor, then this factor is square root of the number in question;


Code for Factorising Numbers in VB.Net

Actually, we've been doing factors over the last two demonstrations (lessons).

We'll simply check for our factors using the square-root of number range.
We'll start from 1 (which is always a factor).
For each found factor, we'll get the corresponding complementary factor by dividing the number (whose factors we are trying to find), by the found factor.


Create a new class file; Project, Add Class.
Call it listFactors.vb.
Optionally, create a new module file; Project, Add Module.
Call it ListFactorsModule.vb.

Type out the adjoining Visual Basic (VB.Net) code for listing the factors of any number.


Note: You can just reuse the main module from the previous lesson if you have been following.









<< PreviousNext >>