Created
January 22, 2022 22:22
-
-
Save CodeMaster7000/3c550ae9b8a5a7006e07633fffaf6765 to your computer and use it in GitHub Desktop.
A program in R to find the H.C.F. of any 2 integers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| hcf <- function(x, y) { | |
| if(x > y) { | |
| smaller = y | |
| } else { | |
| smaller = x | |
| } | |
| for(i in 1:smaller) { | |
| if((x %% i == 0) && (y %% i == 0)) { | |
| hcf = i | |
| } | |
| } | |
| return(hcf) | |
| } | |
| num1 = as.integer(readline(prompt = "Enter first number: ")) | |
| num2 = as.integer(readline(prompt = "Enter second number: ")) | |
| print(paste("The H.C.F. of", num1,"and", num2,"is", hcf(num1, num2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment