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)

9th Sep 2021, 9:00 AM
Amala Yakin
6 odpowiedzi
+ 2
AML Yakin Instead don't make function and use loop directly and print res
9th Sep 2021, 9:16 AM
A͢J
A͢J - avatar
+ 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)
9th Sep 2021, 9:10 AM
A͢J
A͢J - avatar
+ 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, 5:59 AM
Cmurio
Cmurio - avatar
+ 1
AML Yakin No you still have to use {} and also need to call function
9th Sep 2021, 9:15 AM
A͢J
A͢J - avatar
+ 1
To check if your code is correct, you can copy it and run it on playground – and see if it outputs as expected
9th Sep 2021, 11:01 AM
Lisa
Lisa - avatar
0
Now i do some correction, is it right?
9th Sep 2021, 9:13 AM
Amala Yakin