+ 2
If statement in R
x <- readLines('stdin') num <- as.integer(x[1]) x <- 2 if(x%%2==0) { print("even") } else { print("odd") } Where is the error in this program?
3 Respuestas
+ 4
You're making no use of the input. Since you assign the value 2 to x the code will always print "even", no matter what the input is.
+ 4
x <- readLines('stdin')
num <- as.integer(x[1])
if(num%%2==0) print("even") else print("odd")
+ 2
Thank you