Check if two Integer are anagrams of each other | C ++ implementation of the approach ; Function that returns true if a and b are anagarams of each other ; Converting numbers to strings ; Checking if the sorting values of two strings are equal ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool areAnagrams ( int a , int b ) { string c = to_string ( a ) ; string d = to_string ( b ) ; sort ( c . begin ( ) , c . end ( ) ) ; sort ( d . begin ( ) , d . end ( ) ) ; if ( c == d ) return true ; else return false ; } int main ( ) { int a = 240 ; int b = 204 ; if ( areAnagrams ( a , b ) ) cout << " Yes " ; else cout << " No " ; }