If you want to start learning the R programming or you have a bit knowledge about R programming, then this tutorial will help you to explore more. In this tutorial, we are going to share a **R program to check Prime Number** with an example.

Copy the below code and execute it to see the program output.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | num = as.integer(readline(prompt="Enter a number: ")) flag = 0 # prime numbers are greater than 1 if(num > 1) { # check for factors flag = 1 for(i in 2:(num-1)) { if ((num %% i) == 0) { flag = 0 break } } } if(num == 2) flag = 1 if(flag == 1) { print(paste(num,"is a prime number")) } else { print(paste(num,"is not a prime number")) } |

Enter a number: 25

“25 is not a prime number”

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

- Sum of Natural Numbers Using Recursion
- r program for factorial using recursion
- R program to find L.C.M. with the output
- R program to take input from user with the output
- Convert decimal into binary using recursion in R
- Odd or Even program in R programming
- R program to check armstrong number
- R program to find the sum of natural numbers
- r practice problems for beginners
- R Program to Check for Leap Year with the output

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkNoPrivacy policy