Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. //Default size of array
  8. const int m = 8;
  9. //Loop variables and count to store values in C array
  10. int i, j, k,t = 1;
  11. //Array A
  12. int A[m] = {2,3,4,-5,4,-2,-8,4};
  13. // Array B
  14. int B[m] = {1,2,3,-7,-9,-1,0,1};
  15. //Array C
  16. int C[m] = {9};
  17. //Storing negative values from B to C array
  18. for (i = 1; i < m; i++) {
  19. if (B[i] < 0) {
  20. C[t] = B[i];
  21. t++;
  22. }
  23. }
  24.  
  25. //Storing negative values from A to C array
  26. for (j = 1; j < m; j++) {
  27. if (A[j] < 0) {
  28. C[t] = A[j];
  29. t++;
  30. }
  31. }
  32.  
  33. //Putting default value to the end of array
  34. C[t] = 12;
  35.  
  36. //Printing the value of array C
  37. for (k = 0; k < m; k++) {
  38. cout << C[k] << "\n";
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement