Log in from a computer to take this course

You'll need to log in from a computer to start Learn C++. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

Congratulations! You have learned about how to store groups of data into vectors in C++. 🙌

Here are some of the things that we learned:

  • Vectors are a sequence of elements that you can access by an index.

    std::vector<int> even = {2, 4, 6, 8, 10};
  • The first index in a vector is 0.

  • Some of the functions that come with vectors:

    • .push_back()
    • .pop_back()
    • .size()
  • We can use a for loop to iterate through a vector.

Instructions

1.

Optional: Write a program to find the sum of even numbers and the product of odd numbers in a vector.

For example:

Suppose we have a vector that is {2, 4, 3, 6, 1, 9}.

Then the program should output:

Sum of even numbers is 12 Product of odd numbers is 27

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?