Palindromeofnumber Algorithm

The Palindromeofnumber Algorithm is a technique used to determine if a given number is a palindrome or not. A palindrome is a word, phrase, number, or other sequences of characters that reads the same forward and backward. In the context of numbers, a palindromic number is a number that remains the same when its digits are reversed. For example, the numbers 121, 1221, and 12321 are palindromes, while the numbers 123, 12421, and 12345 are not. The algorithm essentially involves reversing the digits of the given number and checking whether the reversed number is equal to the original number. The Palindromeofnumber Algorithm starts by initializing a variable, say 'reversed', to store the reversed number and a temporary variable to store the original number. The algorithm then iterates through each digit of the number from right to left, multiplying the 'reversed' variable by 10, and adding the last digit of the number. It then removes the last digit from the temporary variable by dividing it by 10. This process is repeated until the temporary variable becomes zero. Once the loop is complete, the 'reversed' variable will hold the reversed number. Finally, the algorithm checks whether the original number is equal to the reversed number. If they are equal, the number is a palindrome; otherwise, it is not. This algorithm is efficient and works well for both small and large numbers.
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int num;
	cout << "Enter number = ";
	cin >> num;

	string s1 = to_string(num);
	string s2 = s1;

	reverse(s1.begin(), s1.end());

	if (s1 == s2)
		cout << "true";
	else
		cout << "false";

	return 0;
}

LANGUAGE:

DARK MODE: