Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- void sort(int*, int);
- int main()
- {
- int n;
- cin >> n;
- int *a = new int[n];
- for (int i = 0; i < n; i++)
- cin >> a[i];
- sort(a, n);
- for (int i = 0; i < n; i++)
- cout << a[i] << " ";
- cout << endl;
- return 0;
- }
- void sort(int*a, int n)
- {
- int tmp;
- int tmp_value;
- for (int i = 0; i < n - 1; i++)
- {
- tmp = i;
- for (int j = i+1; j < n; j++)
- if (fabs(a[tmp]) < fabs(a[j]))
- tmp = j;
- tmp_value = a[tmp];
- a[tmp] = a[i];
- a[i] = tmp_value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement