Adam Number | CPP program to check Adam Number ; To reverse Digits of numbers ; To square number ; To check Adam Number ; Square first number and square reverse digits of second number ; If reverse of b equals a then given number is Adam number ; Driver program to test above functions
#include <bits/stdc++.h> NEW_LINE using namespace std ; int reverseDigits ( int num ) { int rev = 0 ; while ( num > 0 ) { rev = rev * 10 + num % 10 ; num /= 10 ; } return rev ; } int square ( int num ) { return ( num * num ) ; } bool checkAdamNumber ( int num ) { int a = square ( num ) ; int b = square ( reverseDigits ( num ) ) ; if ( a == reverseDigits ( b ) ) return true ; return false ; } int main ( ) { int num = 12 ; if ( checkAdamNumber ( num ) ) cout << " Adam ▁ Number " ; else cout << " Not ▁ a ▁ Adam ▁ Number " ; return 0 ; }