LCM of digits of a given number | CPP program to find LCM of digits of a number ; define lcm function ; If at any point LCM become 0. return it ; driver code
#include <iostream> NEW_LINE #include <boost/math/common_factor.hpp> NEW_LINE using namespace std ; int digitLCM ( int n ) { int lcm = 1 ; while ( n > 0 ) { lcm = boost :: math :: lcm ( n % 10 , lcm ) ; if ( lcm == 0 ) return 0 ; n = n / 10 ; } return lcm ; } int main ( ) { long n = 397 ; cout << digitLCM ( n ) ; return 0 ; }