Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int arr1[]{1, -2, 4, -5, 7, 8, 9, -121, 42, -5, 2};
- int arraySize = sizeof(arr1) / sizeof(int);
- int arr2[arraySize];
- //variable to move along the new array
- int j = 0;
- //processing elements with a minus
- for (int i = 0; i < arraySize; i++) {
- if (arr1[i] < 0) {
- arr2[j] = arr1[i];
- j++;
- }
- }
- //processing elements with zero or plus
- for (int i = 0; i < arraySize; i++) {
- if (arr1[i] >= 0) {
- arr2[j] = arr1[i];
- j++;
- }
- }
- //array output
- for (int i = 0; i < arraySize; i++) {
- cout << arr2[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment