Finding H.C.F. - G.C.D. in Visual Basic (VB.Net)
A common method for finding H.C.F. - G.C.D. is repeated factorization
using only common factors.
If we have the set of numbers 30, 48 and
54 for example, their H.C.F. or G.C.D. is found thus:
Hence, H.C.F. of 30, 48 and 54 = 2 X 3 = 6
Simulating H.C.F. (G.C.D.) in Visual Basic (VB.Net) code
We shall follow the steps below in writing our code.
Step 1:
Do a numerical sort on the set so its first member
is the smallest in the set.
Step 2:
Starting with 2, iteratively check through the set
of numbers for a common factor.
Step 3:
For each common factor, divide every member of the number
set by the common factor.
Step 4:
Repeat from step 2 recursively until there are no more
common factors.
Create a new class file; Project, Add Class.
Call it findHCF.vb.
Optionally, create a new module file; Project, Add Module.
Call it FindHCFModule.vb.
Type out the adjoining Visual Basic (VB.Net) code for finding Highest Common Factor (Greatest Common Divisor).(H.C.F)