Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>>
- int main()
- {
- using namespace std;
- int n, imin, imax, t;
- cout << "Enter n: " << endl;
- cin >> n;
- double* mas = new double[n];
- for (int i = 0; i < n; i++)
- {
- cin >> mas[i];
- }
- double max = mas[0];
- double min = mas[0];
- for (int i = 0; i < n; i++)
- {
- if (mas[i] <= min)
- {
- min = mas[i];
- imin = i;
- }
- if (fabs(mas[i]) >= max)
- {
- max = fabs(mas[i]);
- imax = i;
- }
- }
- if (imax < imin)
- {
- t = imin;
- imin = imax;
- imax = t;
- }
- if (imin == imax)
- {
- cout << "mas was not changed " << endl;
- for (int i = 0; i < n; i++)
- {
- cout << mas[i];
- }
- }
- else
- {
- int b;
- for (int i = imin; i <= imax - 3; i++)
- {
- for (int j = imin + 1; j <= imax - 2 - b; j++)
- if (mas[j] < mas[j + 1])
- {
- int k = mas[j];
- mas[j] = mas[j + 1];
- mas[j + 1] = k;
- }
- b++;
- }
- cout << "new: " << endl;
- cout << imin << endl << imax << endl;
- for (int i = 0; i < n; ++i)
- {
- cout << mas[i];
- }
- }
- delete[] mas;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement