Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int n;
- cout << "Input the number of array elements: ";
- cin >> n;
- int *arr = new int[n], j = 0;
- for (int i = 0; i < n; i++) {
- cin >> arr[i];
- if (arr[i] < 0) {
- j++;
- }
- }
- int *newArr = new int[j], newJ = 0;
- cout << "New array: ";
- for (int i = 0; i < n; i++) {
- if (arr[i] < 0) {
- newArr[newJ] = arr[i];
- cout << newArr[newJ] << endl;
- newJ++;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment