Make all numbers of an array equal | C ++ implementation of the approach ; Function that returns true if all the array elements can be made equal with the given operation ; Divide number by 2 ; Divide number by 3 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool EqualNumbers ( int a [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { while ( a [ i ] % 2 == 0 ) a [ i ] /= 2 ; while ( a [ i ] % 3 == 0 ) a [ i ] /= 3 ; if ( a [ i ] != a [ 0 ] ) { return false ; } } return true ; } int main ( ) { int a [ ] = { 50 , 75 , 150 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; if ( EqualNumbers ( a , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }