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()

9th Sep 2021, 4:32 AM
Amala Yakin
2 Answers
+ 2
You can use the sum method: sum(startNumber : EndNumber) Use this command to learn more about the sum() function: help(sum)
20th Sep 2021, 6:00 AM
Cmurio
Cmurio - avatar
+ 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
9th Sep 2021, 6:20 AM
A͢J
A͢J - avatar