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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,239 questions

56,142 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
...