LCM of First n Natural Numbers | C # program to find LCM of First N Natural Numbers . ; to calculate hcf ; to calculate lcm ; lcm ( a , b ) = ( a * b ) / hcf ( a , b ) ; assign a = lcm of n , n - 1 ; b = b - 1 ; Driver code ; base case ; Function call pass n , n - 1 in function to find LCM of first n natural number
using System ; class GFG { static int hcf ( int a , int b ) { if ( b == 0 ) return a ; return hcf ( b , a % b ) ; } static int findlcm ( int a , int b ) { if ( b == 1 ) return a ; a = ( a * b ) / hcf ( a , b ) ; b -= 1 ; return findlcm ( a , b ) ; } static void Main ( ) { int n = 7 ; if ( n < 3 ) Console . Write ( n ) ; else Console . Write ( findlcm ( n , n - 1 ) ) ; } }