- 5
Anybody help me to solve r program for sum in range?
Sum in range
15 Antworten
+ 10
After #define the function
rangeSum<-function(x,y){
resultado <-0
for(z in x:y)
{
resultado<-resultado+z
}
return(resultado)
}
print(rangeSum(x,y))
DONE
+ 1
Ajay Pradeep need your help I'm still stuck et this level
+ 1
Ajay Pradeep in your code do not create the rangeSum function you create the pow function.
You must create the function
rangeSum <- function(a,b) {
resultado <- 0
for(z in a:b)
{
resultado <- res + z
}
return (resultado)
}
https://code.sololearn.com/czl961wofBE8/?ref=app
+ 1
Just started bro
0
Can you please provide link of your attempt (code)? So that we can look into it and help you out
0
Sir please help
https://www.sololearn.com/learning/eom-project/1147/1574
0
Please show your code and explain the problem clearly. Thanks for understanding.
Happy coding!
0
Hey Ajay Pradeep , you shared the wrong link, it doesn't even opening
Kindly share the link of your code(if any, so far)
0
input <- readLines('stdin')
x <- as.integer(input[1])
y <- as.integer(input[2])
#define the function
pow <- function (x,y)
result <- rangeSum(x, y)
print(result)
0
Ajay Pradeep in your code do not create the rangeSum function you create the pow function.
You must create the function
rangeSum <- function(a,b) {
resultado <- 0
for(z in a:b)
{
resultado <- res + z
}
return (resultado)
}
https://code.sololearn.com/czl961wofBE8/?ref=app
0
input <- readLines('stdin')
x <- as.integer(input[1])
y <- as.integer(input[2])
#define the function
pow <- function (x,y)
result <- rangeSum(x, y)
print(result)
0
rangeSum<- function (x,y){
result<- ((((y+1)-x)/2)*(x+y))
print(result)
}
rangeSum(100, 1000)
- 2
Sum in Range
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.
- 2
Saurabh Kumar Yadav Sir do you know this
- 3
I have done it Sir