Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <time.h>
- #include <chrono>
- #include <fstream>
- #include <sstream>
- #include <algorithm>
- #include <string>
- using namespace std;
- void bubbleSort(int* arr, int n)
- {
- int i, j;
- for (i = 0; i < n - 1; i++)
- for (j = 0; j < n - i - 1; j++)
- if (arr[j] > arr[j + 1])
- swap(arr[j], arr[j + 1]);
- }
- int main() {
- setlocale(LC_CTYPE, "");
- int num;
- cout << "Кiлькiсть елементiв: ";
- cin >> num;
- int* mass = new int[num];
- for (int i = 0; i < num; i++) {
- mass[i] = rand() % 27 - 10;
- cout << mass[i] << "\t";
- }
- cout << "\nВiдсортований масив:" << endl;
- bubbleSort(mass, num);
- for (int i = 0; i < num; i++) {
- cout << mass[i] << "\t";
- }
- cout << "\n\nСума першого та останього елементів масиву: " << mass[0] + mass[num - 1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment