Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,884 questions

51,810 answers

573 users

How to recursively check if a number is palindrome in Pascal

1 Answer

0 votes
program CheckPalindrome;

function IsPalindrome(num, reversed, original: Integer): Boolean;
begin
    // Base case: If the number is reduced to 0, check the reverse against the original number
    if num = 0 then
        IsPalindrome := (reversed = original)
    else
    begin
        // Extract the last digit, update the reversed number, and proceed recursively
        reversed := reversed * 10 + (num mod 10);
        IsPalindrome := IsPalindrome(num div 10, reversed, original);
    end;
end;

var
    number: Integer;
    result: Boolean;
begin
    number := 12321;

    // Call the recursive function
    result := IsPalindrome(number, 0, number);

    if result then
        WriteLn(number, ' is a palindrome.')
    else
        WriteLn(number, ' is not a palindrome.');
end.



(*
run:

12321 is a palindrome.

*)

 



answered Apr 8, 2025 by avibootz
...