Reversible numbers | C ++ program to check if a given number is reversible or not ; Function to check reversible number ; Calculate reverse of n ; Calculate sum of number and its reverse ; Check for reverse number reach digit must be odd ; Driver function
#include <iostream> NEW_LINE #include <cmath> NEW_LINE using namespace std ; void checkReversible ( int n ) { int rev = 0 , rem ; int flag = n ; while ( flag ) { rem = flag % 10 ; rev *= 10 ; rev += rem ; flag /= 10 ; } int sum = rev + n ; while ( sum && ( rem % 2 != 0 ) ) { rem = sum % 10 ; sum /= 10 ; } if ( sum == 0 ) cout << " Reversible ▁ Number " ; else cout << " Non - Reversible ▁ Number " ; } int main ( ) { int n = 36 ; checkReversible ( n ) ; return 0 ; }