+ 2
would you like to help me to complete the module project The Greatest Number on the R . course The Greatest Number for R
The Greatest Number for R
6 Answers
+ 6
Hi there, after reading the course over again, I found that simple solution hahha
input <- readLines('stdin')
x <- as.integer(input[1])
y <- as.integer(input[2])
z <- as.integer(input[3])
print(max(x, y, z))
+ 5
Hello.
First plz show us ur attempts!
+ 2
The greatest number would be the maximum of a vector. Your code tries to calculate the sum of a vector. So what do you intend to do?
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))
but as I pressed run it say it's wrong so can you help me please
0
Bayu Prayoga
Do you mean that you must sum the total of a range of numbers?
Maybe this could help.
Note the inclusion of curly brackets in the for loop statement.
input <- readLines('stdin')
x <- as.integer(input[1])
y <- as.integer(input[2])
rangeSum <- function(x, y) {
total <- 0
for(num in x:y){
total <- total + num
}
return (total)
}
print(rangeSum(x, y))
0
input <- readLines('stdin')
x <- as.integer(input[1])
y <- as.integer(input[2])
z <- as.integer(input[3])
print(max(x, y, z))