R Program to check odd and even number

How to check the given number is a odd or even

Here we are explaining how to write an R program to take number from the user and check it is an odd or even. we can use the readline() function to take input from the user (terminal). Here the prompt argument can choose to display an appropriate message for the user.

How odd or even number check is implemented in R Program

We are using readline() function for taking the user’s input. Given below are the steps which are used in the R program to read value for odd or even check. In this R program, we accept the user’s values into num by providing an appropriate message to the user using ‘prompt’. Check the given number is even if division by 2 otherwise it is an odd number.

ALGORITHM

R Source Code

# set a number 
num = as.integer(85)
if((num %% 2) == 0) {

  print(paste(num,"is Even number"))
} else {

  print(paste(num,"is Odd number"))
}
## [1] "85 is Odd number"

R Source Code

# set a number 
num = as.integer(62)
if((num %% 2) == 0) {

  print(paste(num,"is Even number"))
} else {

  print(paste(num,"is Odd number"))
}
## [1] "62 is Even number"