Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
?? Solve some Function : GCD/LCM...etc
Message
From
01/05/2011 10:08:20
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
01/05/2011 09:54:36
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP
Application:
Desktop
Miscellaneous
Thread ID:
01508931
Message ID:
01508932
Views:
54
>Hi, all.
>Happy The Holiday of Labors Day.
>Foxer's WORKERS OF ALL LANDS UNITE.
>
>I Need Function : GCD/LCM.
>
>1. GCD
>GCD = Greatest Common Divisor
>Euclid's implementation of the greatest common divisor of two integers.
>e.g
>? F_GCD(9, 6) && Return : 3
>
>2. LCM
>LCM = Least Common Multiple
>(LCM) is the smallest number that two or more numbers will divide into evenly.
>? F_LCM(48, 42) && Return : 2
>
>3. Solve : Indeterminate equation of the first degree
>Finds the positive integral solutions of an indeterminate equation of the first degree of the form { a*X + b*Y = c }
>if can DO, then :
>Fx(Max) = ? and Fy(Max) = ?
>or
>Fx(Min) = ? and Fy(Min) = ?
>X = ? and Y = ?
>e.g :
>if :
>X + 3Y = 12
>Result :
>X = 9, Y = 1
>X = 6, Y = 2
>X = 3, Y = 3
>
>How to ?
>
>VFP Code/Sample
>
>Thanks
>
>FpxPro Funs
>
>- Tuberose
Pseudocode, for greatest common factor (or "divisor", as you called it):
* This uses Euclid's algorithm
function gcf(a, b)
a = first number
b = second number
c = remainder of the division (a % b)
if c is zero, return b.
otherwise, let a = b, then let b = c, and repeat.

Code for least common multiple:
* Uses the fact that a * b = gcf(a, b) * lcm(a, b)
function lcm(a, b)
return(a * b / gcf(a, b)
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform