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,870 questions

51,793 answers

573 users

How to get the square root rounded down to the nearest integer of a positive integer in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Function mySqrt(ByVal n As Integer) As Integer
        If n = 0 OrElse n = 1 Then
            Return n
        End If

        Dim start As Integer = 1
        Dim _end As Integer = n

        While start <= _end
            Dim mid As Integer = start + (_end - start) / 2
            If CLng(mid) * mid > CLng(n) Then
                _end = mid - 1
            ElseIf mid * mid = n Then
                Return mid
            Else
                start = mid + 1
            End If
        End While

        Return _end
    End Function

    Public Shared Sub Main(ByVal args As String())
        Console.WriteLine(mySqrt(240000)) ' 489.897
    End Sub
End Class

 
 
 
' run:
'
' 489
'

 



answered May 12, 2024 by avibootz
edited May 12, 2024 by avibootz

Related questions

...