0
R Programming
What's wrong with this code input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) #define the function result<-0 rangeSum <-function(x,y) for(a in x:y){ result<-result+a print(sum(result)) } rangeSum (x, y)
3 Answers
+ 2
You are also missing the curly brackets that enclose the statement of your function
input <- readLines('stdin')
x <- as.integer(input[1])
y <- as.integer(input[2])
# function definition
result<-0
rangeSum <- function(x,y){
for(a in x:y){
result<-result+a
}
print(sum(result))
}
rangeSum (x, y)
+ 2
Thanks đ
+ 1
Only print the final result, not on each iteration