How to resolve the algorithm Palindrome detection step by step in the PowerBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Palindrome detection step by step in the PowerBASIC programming language
Table of Contents
Problem Statement
A palindrome is a phrase which reads the same backward and forward. Write a function or program that checks whether a given sequence of characters (or, if you prefer, bytes) is a palindrome. For extra credit:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Palindrome detection step by step in the PowerBASIC programming language
Source code in the powerbasic programming language
FUNCTION isPalindrome (what AS STRING) AS LONG
DIM whatcopy AS STRING, chk AS STRING, tmp AS STRING * 1, L0 AS LONG
FOR L0 = 1 TO LEN(what)
tmp = UCASE$(MID$(what, L0, 1))
SELECT CASE tmp
CASE "A" TO "Z"
whatcopy = whatcopy & tmp
chk = tmp & chk
CASE "0" TO "9"
MSGBOX "Numbers are cheating! (""" & what & """)"
FUNCTION = 0
EXIT FUNCTION
END SELECT
NEXT
FUNCTION = ISTRUE((whatcopy) = chk)
END FUNCTION
FUNCTION PBMAIN () AS LONG
DATA "My dog has fleas", "Madam, I'm Adam.", "1 on 1", "In girum imus nocte et consumimur igni"
DIM L1 AS LONG, w AS STRING
FOR L1 = 1 TO DATACOUNT
w = READ$(L1)
IF ISTRUE(isPalindrome(w)) THEN
MSGBOX $DQ & w & """ is a palindrome"
ELSE
MSGBOX $DQ & w & """ is not a palindrome"
END IF
NEXT
END FUNCTION
You may also check:How to resolve the algorithm Vector products step by step in the Raku programming language
You may also check:How to resolve the algorithm Generate lower case ASCII alphabet step by step in the Comal programming language
You may also check:How to resolve the algorithm Subleq step by step in the Scala programming language
You may also check:How to resolve the algorithm Hough transform step by step in the Haskell programming language
You may also check:How to resolve the algorithm Cistercian numerals step by step in the Phix programming language