C++ Program to Check Given Number is Palindrome or Not

C++ Program to Check Given Number is Palindrome or Not

Write C++ Program to Check Given Number is Palindrome or Not

// CPP Program to Check Given Number is Palindrome or Not

#include <iostream>

using namespace std;

int palindrome(int n)
{
	static int ans=0;
	if(n <= 0)
	{
		return ans;
	}

	int remainder = n % 10;
	ans = ans * 10 + remainder;

	palindrome(n / 10);
	return ans;

}
int main()
{
	int n;
	cout << "Enter Number :--> ";
	cin >> n;

	int temp = palindrome(n);

	if(temp == n)
	{
		cout << "Number is Palindrome";
	}
	else
		cout << "Number is not Palindrome";

	return 0;
}

Output:

Run 1:
Enter Number :--> 121
Number is Palindrome

Run 2:
Enter Number :--> 1234
Number is not Palindrome