Untitled

 avatar
unknown
plain_text
a year ago
722 B
9
Indexable
#Return maximum of two numbers
maxnumber <- function(a, b) {
  if(a > b) {
    return(a)
  } else {
    return(b)
  }
}

maxnumber(3, 5)

#Return maximum of three numbers
max3numbers <- function(a, b, c) {
  if(a > b && a > c) {
    return(a)
  } else if(a < b && c < b) {
    return(b)
  } else {
    return(c)
  }
}

max3numbers(1, 2, 3)



#sum of all the numbers in the list

sumofall <- function(numbers) {
return(sum(numbers))  
}

sumofall(c(1, 3, 5, 8, 8, 9, 10, 13, 20, 5, 0))


#average of all the numbers in the list
averageofall <- function(numbers) {
  total_num <- sum(numbers)
  characters_num <- length(numbers)
  
  return(total_num / characters_num)
}

averageofall(c(1, 3, 5, 8, 8, 9, 10, 13, 20, 5, 0))
Editor is loading...
Leave a Comment