Check if a given number is one less than twice its reverse | C ++ program of the above approach ; Iterative function to reverse digits of num ; Loop to extract all digits of the number ; Function to check if N satisfies given equation ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int rev ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } bool check ( int n ) { return 2 * rev ( n ) == n + 1 ; } int main ( ) { int n = 73 ; if ( check ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }