Skip to content

Instantly share code, notes, and snippets.

@CodeMaster7000
Created January 22, 2022 22:22
Show Gist options
  • Select an option

  • Save CodeMaster7000/3c550ae9b8a5a7006e07633fffaf6765 to your computer and use it in GitHub Desktop.

Select an option

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.
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