Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ex1() {
- int a, b, c, n, k=0;
- int temp;
- cout << "Кол-во элементов \n ->";
- cin >> n;
- int* arr = new int[n];
- cout << "Введите элементы\n ->";
- for (int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- for (int i = 0; i < n; i++) {
- cout << arr[i]<< " ";
- }
- cout << endl;
- for (int i = 0; i < n; i++)
- {
- for (int j = i; j < n; j++)
- {
- if (arr[i] == arr[j]) {
- k++;
- break;
- }
- }
- }
- int* arr2 = new int[k];
- c = 0;
- for (int i = 0; i < n; i++)
- {
- for (int j = i; j < n; j++)
- {
- if (arr[i] == arr[j]) {
- arr2[c] = arr[i];
- c++;
- break;
- }
- }
- }
- cout << "Повторений " << c << endl;
- for (int i = k - 1; i >= 1; i--) {
- for (int j = 0; j < i; j++) {
- if (arr2[j] > arr2[j + 1]) {
- temp = arr2[j];
- arr2[j] = arr2[j + 1];
- arr2[j + 1] = temp;
- }
- }
- }
- for (int i = 0; i < k; i++) {
- cout << arr2[i] << " ";
- }
- cout << endl;
- }
- int main() {
- setlocale(0, "");
- ex1();
- // ex2();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment