R/euclidean_Arian.R

#' This is a function that uses the euclidean algorithm
#' @param a is numeric or integer
#' @param b is numeric or integer
#' @export

euclidian_A <- function(a, b) {
  if(!is.numeric(a) | !is.numeric(b)){
    stop("Not a numeric input")
  } else {
    if(b > a){
      temp_a <-a
      temp_b <- b
      a <- temp_b
      b <- temp_a
    }
    r_1 <- a;
    r_2 <- b;
    while(r_2 != 0) {
      r   <- r_1 %% r_2
      r_1 <- r_2
      r_2 <- r
    }
    return(r_1)
  }
}
rebinhosini/AdvancedR documentation built on May 27, 2019, 4:01 a.m.