0
Is it correct or wrong?
input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) rangeSum <-function(x,y){ for (i in x:y) res<-0 res<-i+res } Print(res)
6 odpowiedzi
+ 2
AML Yakin
Instead don't make function and use loop directly and print res
+ 2
AML Yakin
No it is wrong you didn't use opening and closings curly brackets on function definition.
You didn't call function and store returned value to print res
rangeSum <- function (x, y) {
#logic
}
result = rangeSum(x, y)
print (result)
+ 2
You can use the sum method:
sum(startNumber : EndNumber)
Use this command to learn more about the sum() function:
help(sum)
+ 1
AML Yakin
No you still have to use {} and also need to call function
+ 1
To check if your code is correct, you can copy it and run it on playground – and see if it outputs as expected
0
Now i do some correction, is it right?