Skip to content

Instantly share code, notes, and snippets.

@sethprog26
Created May 10, 2021 07:53
Show Gist options
  • Save sethprog26/8cf2250f60b659e42d49adeb6cc3e1a6 to your computer and use it in GitHub Desktop.
Save sethprog26/8cf2250f60b659e42d49adeb6cc3e1a6 to your computer and use it in GitHub Desktop.
Class 8 Drill
#include <iostream>
#include <vector>
int ga[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
void f(int array[], int size) {
int la[10];
for (int i = 0; i < size; i++) {
la[i] = array[i];
}
for(int i = 0; i < 10; i++) {
cout << la[i] << " ";
}
cout << endl;
int* p = new int[size];
for (int i = 0; i < size; i++) {
p[i] = array[i];
}
for (int i = 0; i < size; i++) {
cout << p[i] << " ";
}
cout << endl;
delete [] p;
}
vector<int> gv({1, 2, 4, 8, 16, 32, 64, 128, 256, 512});
void fv(vector<int> vec) {
vector<int> lv;
lv.resize(vec.size());
for(int i = 0; i < vec.size(); i++) {
lv[i] = vec[i];
}
for(int i = 0; i < lv.size(); i++) {
cout << lv[i] << " ";
}
cout << endl;
vector<int> lv2(vec);
for(int i = 0; i < lv2.size(); i++) {
cout << lv2[i] << " ";
}
cout << endl;
}
int main() {
f(ga, 10);
int aa[10] = {
1, 2, 6, 24, 120, 720, 5040, 5040*8, 5040*8*9, 5040*8*9*10
};
f(aa, 10);
fv(gv);
vector<int> vv({1, 2, 6, 24, 120, 720, 5040, 5040*8, 5040*8*9, 5040*8*9*10});
fv(vv);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment