Skip to content
doubtly

1 answer

Best answer

#include <stdio.h>  
#include <conio.h>  
  
int get_lcm( int a, int b); // function declaration   
  
int main()  
{  
    int n1, n2, lcm; // declaration of variables  
    printf (" \n Enter any two positive numbers to get the LCM of: \n ");  
    scanf ("%d %d", &n1, &n2);  
    lcm = get_lcm( n1, n2); // function calling  
    printf ( " \n LCM of %d and %d is %d. ", n1, n2, lcm);  
    return 0;  
}  
  
int get_lcm ( int n1, int n2) // function definition   
{  
    /* static variabe is iniatialized only once for each function call */     
    static int max = 1;  
    if ( max % n1  == 0 && max % n2 == 0)  
    {  
        return max;  
    }  
    else  
    {  
        max++;  
        get_lcm( n1, n2);  
        return max;  
    }  
} 
Doubtly · 11 Jun 2022 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.