Lychrel Number Implementation | C ++ Program to check whether the given number is Lychrel Number or not with given limit on number of iterations . ; Max Iterations ; Function to check whether number is Lychrel Number ; Function to check whether the number is Palindrome ; Function to reverse the number ; Driver program
#include <iostream> NEW_LINE using namespace std ; long reverse ( long ) ; bool isPalindrome ( long ) ; static int MAX_ITERATIONS = 20 ; string isLychrel ( long number ) { for ( int i = 0 ; i < MAX_ITERATIONS ; i ++ ) { number = number + reverse ( number ) ; if ( isPalindrome ( number ) ) return " false " ; } return " true " ; } bool isPalindrome ( long number ) { return number == reverse ( number ) ; } long reverse ( long number ) { long reverse = 0 ; while ( number > 0 ) { long remainder = number % 10 ; reverse = ( reverse * 10 ) + remainder ; number = number / 10 ; } return reverse ; } int main ( ) { long number = 295 ; cout << number << " ▁ is ▁ lychrel ? ▁ " << isLychrel ( number ) ; }