0% found this document useful (0 votes)
73 views

Public Class Dim As String Dim As String Private Sub Byval As Byval As Handles

The document contains code for three Visual Basic applications. The first checks if a string is a palindrome. The second finds if a number belongs to certain categories like strong, perfect or palindrome. The third calculates the factorial of a given number using a function.

Uploaded by

sadhanardd
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Public Class Dim As String Dim As String Private Sub Byval As Byval As Handles

The document contains code for three Visual Basic applications. The first checks if a string is a palindrome. The second finds if a number belongs to certain categories like strong, perfect or palindrome. The third calculates the factorial of a given number using a function.

Uploaded by

sadhanardd
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Program for checking given string is palindrome or not

Public Class Form1

Dim str As String


Dim stringrev As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Button1.Click

str = TextBox1.Text
Dim temp(10) As Char
temp = str.ToCharArray()
Dim n As Integer

n = temp.Length - 1

While (n >= 0)
stringrev = stringrev & temp(n)
n = n - 1
End While

If str = stringrev Then


MsgBox("given string is palindrome")

Else
MsgBox("given string is not palindrome")
End If

stringrev = ""

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Button2.Click
End
End Sub
End Class
Program for binary search
Imports System.Console
Module Module1

Sub accpet(ByRef a() As Integer)


Dim i As Integer

For i = 0 To a.Length - 1
a(i) = Val(ReadLine())
Next i

End Sub

Sub sort(ByRef a() As Integer)

Dim i, j, n, temp As Integer

n = a.Length

For i = 0 To n - 1
For j = i To n - 1

If a(i) > a(j) Then


temp = a(i)
a(i) = a(j)
a(j) = temp
End If

Next
Next

End Sub

Sub display(ByRef a() As Integer)

For i As Integer = 0 To a.Length - 1


WriteLine(a(i))
Next
End Sub

Function bsearch(ByRef a() As Integer, ByVal key As Integer) As


Integer

Dim low As Integer = 0


Dim high, mid As Integer

high = a.Length - 1

While low <= high


mid = (low + high) / 2

If a(mid) = key Then


Return mid
ElseIf a(mid) > key Then
high = mid - 1

Else
low = mid + 1
End If

End While
Return -1
End Function
Sub Main()

Dim a(), n, key, loc As Integer

WriteLine("Enter no of elements")

n = ReadLine()
ReDim a(n)

WriteLine("Enter elements into array")


accpet(a)
sort(a)
WriteLine("Given elements are")
display(a)

WriteLine("Enter element to search")


key = Val(ReadLine)

loc = bsearch(a, key)

If loc = -1 Then
WriteLine("element not found")
Else
WriteLine("element found at" & loc)

End If

Read()
End Sub

End Module

Develop an Visual Basic Application to Check the given number


in one of categories like
i. Strong Number.
ii. Perfect Number.
iii. Palindrome.

Module Module1

Sub strong(ByVal n As Integer)


Dim d, sum, m, i, f As Long
sum = 0
m = n
While n <> 0
d = n Mod 10
f = 1
For i = d To 1 Step -1
f = f * i
Next

sum = sum + f
n = n / 10

End While

If m = sum Then
Console.WriteLine("{0} is a strong number", m)
Else
Console.WriteLine("{0} is not a strong number", m)
End If

End Sub

Sub perfect(ByVal n As Integer)

Dim i As Integer
Dim sum As Integer = 0

For i = 1 To n / 2

If n Mod i = 0 Then
sum = sum + i
End If

Next

If sum = n Then
Console.WriteLine("{0} is a perfect no", n)
Else
Console.WriteLine("{0} is not a perfect no", n)
End If

End Sub

Sub palindrome(ByVal n As Integer)

Dim temp, remainder, sum As Integer


sum = 0

temp = n

While n > 0
remainder = n Mod 10
n /= 10
sum = sum * 10 + remainder
End While

If sum = temp Then


Console.WriteLine("{0} is palindrome", temp)
Else
Console.WriteLine("{0} is not palindrome", temp)
End If

End Sub

Sub Main()
Dim n, ch As Integer

Console.WriteLine("----------------")
Console.WriteLine("1.Strong number")
Console.WriteLine("2.Perfect number")
Console.WriteLine("3.palindrome number")
Console.WriteLine("----------------")

Console.WriteLine("Enter any number")


n = Console.ReadLine()

Console.WriteLine("Enter choice")
ch = Console.ReadLine()

Select Case ch
Case 1
strong(n)
Case 2
perfect(n)
Case 3
palindrome(n)
Case Else
Console.WriteLine("in valid choice")
End Select
Console.Read()

End Sub

End Module

Develop an Visual Basic Application to find out the factorial


of the given number by using functions

Module Module1

Function factorial(ByVal n As Integer) As Long

Dim i As Integer
Dim fact As Long = 1

For i = 1 To n
fact = fact * i
Next

Return fact
End Function

Sub Main()
Dim n As Integer
Dim fact As Long

Console.WriteLine("Enter any number")


n = Console.ReadLine

fact = factorial(n)

Console.WriteLine("{0} factorail is {1}", n, fact)

Console.Read()
End Sub

End Module

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy