Session Ready
Exercise

Indexing a vector

Indexing in C++ starts at 0, so it can help to imagine the index as an offset from the start of the vector. x[0] is at offset 0 and gives the first element of x.

Instructions
100 XP
  • Complete the definition of a function, first_plus_last(), that gives the sum of the first and last values of a NumericVector.
  • Set n to be the size() of x.
  • Set first to be the first element of x.
  • Set last to be the last element of x.