R Programming | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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)

7th Jun 2022, 5:21 PM
Alexander Antobre Dwumah
Alexander Antobre Dwumah - avatar
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)
7th Jun 2022, 10:48 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Thanks 😊
8th Jun 2022, 2:46 AM
Alexander Antobre Dwumah
Alexander Antobre Dwumah - avatar
+ 1
Only print the final result, not on each iteration
7th Jun 2022, 5:41 PM
Lisa
Lisa - avatar