Here we are explaining how to write an R program to check given number is Positive, Negative, or Zero. 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.
We are using readline() function for taking the user’s input. Given below are the steps which are used in the R program to check given number is Positive, Negative or Zero. In this R program, we accept the user’s input into the variable number by providing an appropriate message to the user using ‘prompt’. If the number is greater than zero it is positive. If the number is less than zero it is negative.
number = as.double(56)
if(number > 0) {
print("It is a Positive number")
} else {
if(number == 0) {
print("number is Zero")
}
else {
print("It is a Negative number")
}
}
## [1] "It is a Positive number"
number = as.double(-47)
if(number > 0) {
print("It is a Positive number")
} else {
if(number == 0) {
print("number is Zero")
}
else {
print("It is a Negative number")
}
}
## [1] "It is a Negative number"
number = as.double(0.0)
if(number > 0) {
print("It is a Positive number")
} else {
if(number == 0) {
print("number is Zero")
}
else {
print("It is a Negative number")
}
}
## [1] "number is Zero"