0 votes
313 views
in C programming by (98.9k points)
edited
Write a program to find the LCM of two number using functions.

1 Answer

0 votes
by (98.9k points)
selected by
 
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;  
    }  
} 

 

Related questions

0 votes
1 answer 227 views
0 votes
1 answer 978 views
asked Jul 20, 2022 in C programming by Doubtly (98.9k points)
0 votes
1 answer 129 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

563 users

...