Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void newarr(int* arr, int lenarr)
- {
- for (int i = 0; i < lenarr; i++)
- {
- arr[i] = 0 + rand() % 20;
- }
- cout << "Начальный массив: \n";
- for (int i = 0; i < lenarr; i++)
- {
- cout << arr[i] << " ";
- }
- cout << "\nПолученный массив: \n";
- for (int i = 0; i < lenarr; i++)
- {
- for (int j = i + 1; j < lenarr; j++)
- {
- if (arr[i] == arr[j])
- {
- int wasBefore = 0;
- for (int k = 0; k < i; k++) {
- if (arr[k] == arr[i]) {
- wasBefore = 1; break;
- }
- }
- if (wasBefore == 0) {
- cout << arr[i] << " ";
- }
- break;
- }
- }
- }
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- int n;
- cout << "Введите число n:\n";
- cin >> n;
- int* arr = new int[n];
- newarr(arr, n);
- delete[]arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement