write VBA sub program 1. Understand Nested For-Loop statements 2. Use Sorting me
ID: 3759443 • Letter: W
Question
write VBA sub program 1. Understand Nested For-Loop statements 2. Use Sorting methods 3. Use Arrays Task: Median, GCD and LCM Write a VBA Sub program to get 3 positive numbers as inputs from the user and check for positive numeric values. For valid inputs, the program should calculate the median. The program should also calculate the greatest common divisor (GCD) and least common multiple (LCM) between the smallest and the largest numbers from the 3 user input values. Note: Don?t use inbuilt MEDIAN, LCM and GCD functionsExplanation / Answer
Answer :
Function calcLCM(n1 As Long, n2 As Long) As Long
' Returns the least common multiple of n1 and n2
calcLCM = n1 * n2 / vGCD(n1, n2)
End Function
Function calcGCD(ByVal n1 As Long, ByVal n2 As Long) As Long
' Returns the greatest common divisor of n1 and n2
Dim i As Long
Do While n2 <> 0
i = n2
n2 = n1 Mod n2
n1 = i
Loop
calcGCD = n1
End Function
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.