0
Where is query in my code?
input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) rangeSum <-function(x,y) result<-0 for(i in x:y){ return(result+i) } rangeSum()
2 Answers
+ 2
You can use the sum method:
sum(startNumber : EndNumber)
Use this command to learn more about the sum() function:
help(sum)
+ 2
AML Yakin
Return statement should be outside loop otherwise loop will break after first iteration and value will be return back to the function.
Also you didn't pass values in function
You have to do inside loop : result <- result + i
Then return result outside the loop