Use VBA a) Write a user-defined function LargerOf2 that finds the larger number
ID: 3725532 • Letter: U
Question
Use VBA a) Write a user-defined function LargerOf2 that finds the larger number between two real numbers n1 and n2. b) Test your function LargerOf2 by writing a main procedure, which has the user to input the 3 sides of a triangle, calls the function 2 times to find largest side of the triangle , and displays the result with a message box. Test your program with s1=4.5, s2=2.2, s3=5.1.
Explanation / Answer
Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Text.RegularExpressions Namespace Program Public Module Program Function LargerOf2(x1 As Double, x2 As Double) As Double If x1 > x2 Then return x1 Else return x2 End If End Function Public Sub Main(args() As string) Dim x as Double, y as Double, z as Double, max as Double Console.Write("Enter side 1: ") x = Convert.ToDouble(Console.ReadLine()) Console.Write("Enter side 2: ") y = Convert.ToDouble(Console.ReadLine()) Console.Write("Enter side 3: ") z = Convert.ToDouble(Console.ReadLine()) max = LargerOf2(x, y) max = LargerOf2(max, z) Console.WriteLine("Largest side of the triangle is " + max.ToString()) End Sub End Module End Namespace
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.