File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed 
Learning/7. Challenges/3. Functions Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ // Program to find LCM (Lowest Common Multiple) of two numbers using a function. 
2+ 
3+ #include  <stdio.h> 
4+ 
5+ int  findLCM (int  num1 , int  num2 ) {// create function findLCM() with parameters num1 and num2 
6+  
7+  int  lcm ;// compute lcm of two values and return it 
8+  
9+  if  (num1  >= num2 ) {
10+  lcm  =  num1 ;
11+  }
12+  else  {
13+  lcm  =  num2 ;
14+  }
15+  
16+  while  (1 ) {
17+  lcm  =  lcm  +  1 ;
18+  if  (lcm  % num1  ==  0  &&  lcm  % num2  ==  0 ) {
19+  break ;
20+  }
21+  }
22+  return  lcm ;
23+ }
24+ 
25+ int  main () {
26+  
27+  int  x , y ;// get input value for x and y 
28+  scanf ("%d %d" , & x , & y );
29+ 
30+  int  lcm  =  findLCM (x , y );// call findLCM() with arguments x and y 
31+ 
32+  printf ("%d" , lcm );// print the returned value 
33+  
34+  return  0 ;
35+ }
                                 You can’t perform that action at this time. 
               
                  
0 commit comments