Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Ex 6: Create a function that will return TRUE if an input integer is prime. Otherwise, return FALSE. You may want to look into the any() function.
- prime_check <- function (number) {
- is.prime <- T
- if (number == 2) {
- is.prime <- T
- } else if (any(number %% (2:(number - 1)) == 0)) {
- is.prime <- F
- }
- return(is.prime)
- }
- prime_check(1)
- prime_check(2)
- prime_check(5)
- prime_check(4)
- prime_check(237)
- prime_check(131)
Add Comment
Please, Sign In to add comment