Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,894 questions

51,825 answers

573 users

How to calculate the LCM (Least Common Multiple) of 3 numbers in VB.NET

2 Answers

0 votes
Imports System

Public Class Program
	Public Shared Function getLMC(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) As Integer
        Dim lmc As Integer = Math.Max(Math.Max(a, b), c)

        While True
            If lmc Mod a = 0 AndAlso lmc Mod b = 0 AndAlso lmc Mod c = 0 Then
                Return lmc
            End If
	        lmc += 1
        End While
		return -1
    End Function

    Public Shared Sub Main()
        Dim a As Integer = 12, b As Integer = 15, c As Integer = 40
		
        Console.WriteLine("The LCM (Least Common Multiple) is: {0}", getLMC(a, b, c))
    End Sub
End Class

		
		
		

' run:
' 
' The LCM (Least Common Multiple) is: 120
'			
		

 



answered Aug 17, 2021 by avibootz
edited Aug 17, 2021 by avibootz
0 votes
Imports System

public Class Program
	public  Shared Function getLMC(ByVal a As Integer, ByVal b As Integer) As Integer
        Dim lmc As Integer = If((a > b), a, b)

        While True
			If lmc Mod a = 0 AndAlso lmc Mod b = 0 Then
                Return lmc
            End If
            lmc += 1
        End While

			return -1
    End Function

	public Shared Sub Main()
        Dim a As Integer = 12, b As Integer = 15, c As Integer = 40
			
        Console.WriteLine("The LCM (Least Common Multiple) is: {0}", getLMC(getLMC(a, b), c))
    End Sub
End Class

		
		
		

' run:
' 
' The LCM (Least Common Multiple) is: 120
'		
		

 



answered Aug 17, 2021 by avibootz

Related questions

...