CLS
INPUT "Enter string to be tested: ";t$ t$=LCASE$(t$) FOR I=LEN(t$) TO 1 STEP -1 r$=r$+MID$(t$, I, 1)
NEXT I
IF r$=t$ THEN PRINT t$; " is Palindrome!"
ELSE
PRINT t$; " is not Palindrome!"
ENDIF
END
Counting vowels in the given string using User Defined Functions
DECLARE FUNCTION countvow(s$)
CLS
INPUT "Enter testing string=";v$
PRINT "Number of vowels=";countvow(v$)
END
FUNCTION countvow(s$)
FOR i=1 TO LEN(s$) ch$=LCASE$(MID$(s$, i, 1)) SELECT CASE ch$ CASE "a", "e", "i", "o", "u" cnt=cnt+1 END SELECT
NEXT i countvow=cnt END FUNCTION
Generate Fibonacci series using Sub Routine
REM a, b, n parameters represents first term, second term and number of terms respectively
DECLARE SUB fibo(a, b, n)
CLS
INPUT "First Term="; x
INPUT "Second Term=";y
REM label number is for data validation that length of terms must be less or equal to 20
10:
INPUT "How many terms="; z
IF z>20 THEN 10
CALL fibo(x, y, z)
END
SUB fibo(a, b, n)
PRINT a, b,
REM first two terms are already printed so started from 3
FOR I = 3 to n s=a+b PRINT s, a=b b=s
NEXT I
END SUB
Sum of digits of a number using User Defined Function (UDF)
DECLARE FUNCTION digitsum(n)
CLS
INPUT "Enter testing number=";v
PRINT "Sum of ";n;" is "; digitsum(v)
END
FUNCTION digitsum(n) a=n WHILE NOT a=0 'writing NOT a=0 is same as writing a0 r=n MOD 10 s=s+r n=int(n/10)
WEND
digitsum=s
END FUNCTION
Testing Armstrong Number using User Defined Function
DECLARE FUNCTION arm(n)
CLS
INPUT "Enter a testing number=";v
IF arm(v)=1 THEN PRINT v;" is Armstrong Number"
ELSE
PRINT v; " is not Armstrong Number"
ENDIF
END
FUNCTION arm(n) f=0 a=n
WHILE a0 r=a MOD 10 s=s+r^3 a=int(a/10)
WEND
IF s=n THEN f=1 arm=f END FUNCTION
Testing Palindrome Using Function...End Function
DECLARE FUNCTION rev$(s$)
CLS
INPUT "Enter string to be tested"; t$