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.

40,011 questions

51,958 answers

573 users

How to check if a number is cyclops (number with odd number of digits and zero in the center) in VB.NET

1 Answer

0 votes
' A number with an odd number of digits and zero in the center is Cyclops number

Imports System

Public Class Program
    Private Shared Function isCyclopsNumber(ByVal n As Integer) As Boolean
        If n = 0 Then
            Return True
        End If

        Dim m As Integer = n Mod 10
        Dim count As Integer = 0

        While m <> 0
            count += 1
			n = n \ 10
            m = n Mod 10
        End While

        n = n \ 10
		m = n Mod 10

        While m <> 0
            count -= 1
			n = n \ 10
            m = n Mod 10
        End While

        Return n = 0 AndAlso count = 0
    End Function

    Public Shared Sub Main(ByVal args As String())
        Console.WriteLine((If(isCyclopsNumber(209), "yes", "no")))
        Console.WriteLine((If(isCyclopsNumber(18037), "yes", "no")))
        Console.WriteLine((If(isCyclopsNumber(5604), "yes", "no")))
    End Sub
End Class


	
	
	
	
' run:
'
' yes
' yes
' no
'

 



answered Apr 10, 2023 by avibootz
...