Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- //i must use 5 loops for this exercise! Thank you all!
- int main() {
- int a; cout << "size array:" << endl; cin >> a;
- int b [a], c[a] , *d = new int[2*a]; //pointer is twice the size of arrays
- int f = -1;
- int k = 0;
- cout << endl;
- //I must initialized two array, the second with the opposite value of the first.
- for(int e=0; e < a ; e++){int i; cout << "init. first array:" << endl; cin >> i; b[e] = i;}
- for(int e : b) { f++; c[f] = -e;} //cout << c[f] << endl
- //now i must initialized the pointer's first half value with the sum of the respective value for each position in arrays
- do
- d[k] = b[k] + c[k];
- while( ++ k < a);
- //now the second half but with difference
- while(k++ < 2*a) d[k] = b[k] - c[k];
- //result it has to be 4 numbers: a -a 0 2a
- for(int e=0,m=a; e < a; e++, m++) { cout << b[e] << " "<< c[e] <<" "<< d[e] <<" "<< d[m] << endl;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement