R Program to check a number is prime or not


In this program, You will learn how to check a number is prime or not in R.


Some list of Prime numbers is : 2, 3, 5, 7, 11, 13, 17, 19

Example: How to check a number is prime or not in R

{
    n = as.integer(readline(prompt = "Enter a number :"))
    f = 1
    i = 2
    while (i <= n / 2) {
      if (n %% i == 0) {
        f = 0

        break
      }
      i = i + 1
    }

    if (f == 1) {
      print(paste("Number is prime :", n))
    } else{
      print(paste("Number is not prime :", n))

    }
}

Output:

Enter a number :7
[1] "Number is prime : 7"

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.