Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "RUS");
- int k, count = 0;
- cout << "Введите количество членов массива: ";
- cin >> k;
- int* arr = new int[k];
- int* temp = new int[k];
- for (int i = 0; i < k; i++)
- {
- temp[i] = 0;
- arr[i] = rand() % 15 - 9;
- cout << "\nA[" << i << "]: " << arr[i];
- }
- for (int i = 0; i < k; i++)
- {
- if (arr[i] < 0)
- count++;
- }
- int j = 0, n = k - (k - count);
- for (int i = 0; i < k; i++)
- {
- if (arr[i] < 0) {
- temp[j] = arr[i];
- j++;
- }
- else {
- temp[n] = arr[i];
- n++;
- }
- }
- arr = temp;
- cout << endl;
- for (int i = 0; i < k; i++)
- {
- cout << "\t" << arr[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement