How to resolve the algorithm Palindrome detection step by step in the Modula-2 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Palindrome detection step by step in the Modula-2 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 Modula-2 programming language
Source code in the modula-2 programming language
MODULE Palindrome;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,ReadChar;
PROCEDURE IsPalindrome(str : ARRAY OF CHAR) : BOOLEAN;
VAR i,m : INTEGER;
VAR buf : ARRAY[0..63] OF CHAR;
BEGIN
i := 0;
m := HIGH(str) - 1;
WHILE i
IF str[i] # str[m-i] THEN
RETURN FALSE
END;
INC(i)
END;
RETURN TRUE
END IsPalindrome;
PROCEDURE Print(str : ARRAY OF CHAR);
VAR buf : ARRAY[0..63] OF CHAR;
BEGIN
FormatString("%s: %b\n", buf, str, IsPalindrome(str));
WriteString(buf)
END Print;
BEGIN
Print("");
Print("z");
Print("aha");
Print("sees");
Print("oofoe");
Print("deified");
Print("Deified");
Print("amanaplanacanalpanama");
Print("ingirumimusnocteetconsumimurigni");
ReadChar
END Palindrome.
You may also check:How to resolve the algorithm Yahoo! search interface step by step in the Perl programming language
You may also check:How to resolve the algorithm Permutations by swapping step by step in the Arturo programming language
You may also check:How to resolve the algorithm Almost prime step by step in the C# programming language
You may also check:How to resolve the algorithm Hailstone sequence step by step in the C programming language
You may also check:How to resolve the algorithm Binary digits step by step in the M2000 Interpreter programming language