Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int getMaxFromArray(int array[], int n)
- {
- int max = array[1];
- int poz = 1;
- for (int i = 1; i <= n; i++)
- {
- if (array[i] > max) {
- max = array[i];
- poz = i;
- }
- }
- return poz;
- }
- void getMinFromArray(int array[], int n, int& result)
- {
- int min = array[1];
- int poz = 1;
- for (int i = 1; i <= n; i++)
- {
- if (array[i] < min) {
- min = array[i];
- poz = i;
- }
- }
- result = poz;
- }
- void swap(int& a, int& b)
- {
- int aux = a;
- a = b;
- b = aux;
- }
- void afisare(int vector[], int pozInit, int pozFin)
- {
- for (int i = pozFin; i <= pozInit; i++)
- {
- cout << vector[i] << " ";
- }
- cout << endl;
- }
- void sortare(int vector[], int pozInit, int pozFin)
- {
- for (int i = pozInit; i <= pozFin - 1; i++)
- for (int j = i + 1; j <= pozFin; j++)
- if (vector[i] < vector[j])
- swap(vector[i], vector[j]);
- }
- int main()
- {
- int vector[10], n, pozInit, pozFin;
- cout << "n = "; cin >> n;
- for (int i = 1; i <= n; i++)
- {
- cout << "vector[" << i << "] = ";
- cin >> vector[i];
- }
- pozFin = getMaxFromArray(vector, n);
- getMinFromArray(vector, n, pozInit);
- sortare(vector, pozInit, pozFin);
- cout << "Poz init: " << pozInit << endl;
- cout << "Poz fin: " << pozFin << endl;
- afisare(vector, pozInit, pozFin);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment