-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectors.cpp
More file actions
34 lines (24 loc) · 770 Bytes
/
Copy pathVectors.cpp
File metadata and controls
34 lines (24 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <vector>
int main() {
std::vector<int> numbers; // Declare an empty vector of integers
// TODO: Add 5 numbers to the vector using push_back()
numbers.push_back(10);
numbers.push_back(20);
numbers.push_back(30);
numbers.push_back(40);
numbers.push_back(50);
// TODO: Print out all the numbers in the vector using a for loop
for (int num : numbers) {
std::cout << num << " ";
}
std::cout << std::endl;
// TODO: Remove the last number from the vector
numbers.pop_back();
// TODO: Print the size of the vector after removal
for (int num : numbers) {
std::cout << num << " ";
}
std::cout << std::endl;
return 0;
}