Wednesday, April 14, 2010

Algorithm to check palindrome

Word="level"
lengthVar = Len(Word)
For i = 1 To lengthVar
v1 = v1 + Mid(Word, i, 1)
Next
For i = lengthVar To 1 Step -1
v2 = v2 + Mid(Word, i, 1)
Next
If v1 = v2 Then
MsgBox "given word is palindrome"
Else
MsgBox "given word is not palindrome "
End If

No comments: