0

Can you help me to solve this in R language ??

You need to create a function that takes two parameters and returns the sum of all numbers between the two parameters inclusive. The given code takes two numbers from input and passes them to a function called rangeSum(). Task Define the rangeSum() function, so that the code works as expected. Sample Input 4 9 Sample Output [1] 39 Explanation For the inputs 4 and 9, the returned value should be 39.

3rd Sep 2021, 9:25 AM
Niloufar Kashanian
Niloufar Kashanian - avatar
16 Respostas
+ 18
input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) rangeSum <- function(x, y) { s=0 for (n in x:y) s <- s + n return (s) } print(rangeSum(x, y))
3rd Sep 2021, 9:54 AM
SoloProg
SoloProg - avatar
+ 4
input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) z <- as.integer(input[3]) print (max(x,y,z)) // Try not to follow me
7th Aug 2022, 8:34 AM
Abdul Bari Rahmani
Abdul Bari Rahmani - avatar
+ 2
input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) rangeSum <- function(x, y) { s=0 for (n in x:y) s <- s + n return (s) } print(rangeSum(x, y))
15th Dec 2021, 6:52 AM
Marvin Manaog
Marvin Manaog - avatar
+ 1
I don't really like how SoloProg handed out the solution to you and you even marked it as best . Maybe he should have printed the steps you should follow or let you know the concepts that you need to learn and post your attempt first to help you. Sololearn is a self learning platform not a coding agency . But then people do what they want as i am no one to say what one should do .
3rd Sep 2021, 10:02 AM
Abhay
Abhay - avatar
+ 1
My code: input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) rangeSum <- function(x, y) { s=0 for (n in x:y) s <- s + n return (s) } print(rangeSum(x, y))
18th May 2022, 9:15 AM
AKMAL ABDURAHMONOV
AKMAL ABDURAHMONOV - avatar
+ 1
#define the function sum<-function(x,y){ g=0 for (n in x:y) { g<-g+n } return (g) } input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) print(sum(x,y))
24th Jun 2023, 7:37 AM
Abhisheik R
Abhisheik R - avatar
0
Niloufar Kashanian If you post your attempt, then people who are familiar with R will be able to help you resolve the problem. PS: I have only just started to learn R, so would like to see the concept
3rd Sep 2021, 9:41 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
You need to create a function that takes two parameters and returns the sum of all numbers between the two parameters inclusive. The given code takes two numbers from input and passes them to a function called rangeSum(). Task Define the rangeSum() function, so that the code works as expected. Sample Input 4 9 Sample Output [1] 39 Explanation For the inputs 4 and 9, the returned value should be 39.
15th Dec 2021, 6:00 AM
Marvin Manaog
Marvin Manaog - avatar
0
input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) rangeSum <- function(x, y) { s=0 for (n in x:y) s <- s + n return (s) } print(rangeSum(x, y))
15th Dec 2021, 1:49 PM
Marvin Manaog
Marvin Manaog - avatar
0
rangeSum<-function(x,y){ sum<-0 for(i in x:y){ sum<-sum+i } return(sum) } result <- rangeSum(x, y) print(result)
21st Jul 2022, 7:14 PM
Ihabtaher Alasttal
0
input <- readLines('stdin') a <- as.integer(input[1]) b <- as.integer(input[2]) rangeSum <- function(a, b) { p=0 for (n in a:b) p <- p + n return (p) } result <- rangeSum(a, b) print(result)
12th Aug 2022, 10:46 AM
Soundaravalli M
Soundaravalli M - avatar
0
input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) rangeSum <- function(x,y){ sum <-0 for(i in x:y) sum <-sum + i print (sum) } rangeSum(x,y)
28th Jan 2023, 3:05 PM
AL walid
AL walid - avatar
0
x <- readLines('stdin') print(x[read ])
14th Feb 2023, 6:32 AM
VISHWA M
VISHWA M - avatar
- 1
input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) rangeSum <- function(x, y) { s=0 for (n in x:y) s <- s + n return (s) } print(rangeSum(x, y))
16th Dec 2021, 9:52 AM
Mirmahmud Ilyosov
Mirmahmud Ilyosov - avatar
- 1
input <- readLines('stdin') x <- as.integer(input[1]) y <- as.integer(input[2]) rangeSum <- function(x, y) { s=0 for (n in x:y) s <- s + n return (s) } print(rangeSum(x, y))
1st Mar 2022, 9:02 AM
Kondwani Mwafulilwa
Kondwani Mwafulilwa - avatar