Q:

Write C++ program to check palindrome number using recursion

0

Write C++ program to check palindrome number using recursion

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.

#include <iostream>
#include <math.h>
using namespace std;
 
// Function declarations
int reverseNumber(int num);
int isPalindrome(int num);
 
int main()
{
    int num;
 
    // Inputting any number from user
    cout<<"Enter any number: ";
    cin>>num;
 
    if(isPalindrome(num) == 1)
    {
        cout<<num<<" is palindrome number";
    }
    else
    {
        cout<<num<<" is NOT palindrome number";
    }
 
    return 0;
}
 
 
int isPalindrome(int num)
{
 
    if(num == reverseNumber(num))
    {
        return 1;
    }
 
    return 0;
}
 
 
int reverseNumber(int num)
{
    // Finding number of digits in num
    int digit = (int)log10(num);
 
 
    if(num == 0)
        return 0;
 
    return ((num%10 * pow(10, digit)) + reverseNumber(num/10));
}

Result:

Enter any number: 121

121 is palindrome number

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write C++ program to find maximum and minimum elem... >>
<< Write C++ program to find factorial of a number us...