If you want to start learning the R programming or you have a bit knowledge about R programming, then this tutorial will help you to explore more. In this tutorial, we are going to share a how to Find L.C.M in R Programming with an example.
Copy the below code and execute it to see the program output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | lcm <- function(x, y) { # choose the greater number if(x > y) { greater = x } else { greater = y } while(TRUE) { if((greater %% x == 0) && (greater %% y == 0)) { lcm = greater break } greater = greater + 1 } return(lcm) } # take input from the user num1 = as.integer(readline(prompt = "Enter first number: ")) num2 = as.integer(readline(prompt = "Enter second number: ")) print(paste("The L.C.M. of", num1,"and", num2,"is", lcm(num1, num2))) |
Enter first number: 24
Enter second number: 25
The L.C.M. of 24 and 25 is 600
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.