daily pastebin goal
15%
SHARE
TWEET

exercise

onehalf93 Dec 9th, 2018 (edited) 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. using namespace std;
  3. //i must use 5 loops for this exercise! Thank you all!
  4.  
  5. int main() {
  6. int a; cout << "size array:" << endl; cin >> a;
  7. int b [a], c[a] , *d = new int[2*a]; //pointer is twice the size of arrays
  8. int f = -1;
  9. int k = 0;
  10.  
  11. cout << endl;
  12.  
  13. //I must initialized two array, the second with the opposite value of the first.
  14.  
  15.     for(int e=0; e < a ; e++){int i; cout << "init. first array:" << endl; cin >> i; b[e] = i;}
  16.     for(int e : b) { f++; c[f] = -e;} //cout << c[f] << endl
  17.  
  18. //now i must initialized the pointer's first half value with the sum of the respective value for each position in arrays
  19.  
  20.     do 
  21.          d[k] = b[k] + c[k];
  22.     while( ++ k < a);
  23.  
  24. //now the second half but with difference
  25.  
  26.        
  27.         while(k++ < 2*a)  d[k] = b[k] - c[k];
  28.  
  29. //result it has to be 4 numbers: a -a 0 2a
  30. for(int e=0,m=a; e < a; e++, m++) { cout << b[e] << " "<< c[e] <<" "<< d[e] <<" "<< d[m] << endl;}
  31.  
  32.    
  33.  
  34.        
  35.    
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top