Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int normpow(int x, int y)
- {
- int result;
- result = 1;
- while (y > 0)
- {
- result = result * x;
- y--;
- }
- return result;
- }
- void bSort(int list[], int listLen)
- {
- for (int m = 0; m < listLen; m++)
- {
- bool flag = true;
- for (int i = 0; i < listLen - 1; i++)
- {
- if (list[i] > list[i + 1])
- {
- swap(list[i], list[i + 1]);
- flag = false;
- }
- }
- if (flag == true)
- break;
- }
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- int num;
- cout << "Введите размер массива" << endl;
- cin >> num;
- int* a = new int[num];
- srand(time(0));
- for (int i = 0; i < num; i++)
- {
- a[i] = (rand() * normpow(-1, rand())) % 1000 + 1;
- cout << a[i] << " - " << i+1 << " элемент массива" << endl;
- }
- bSort(a, num);
- cout << "Отсортированный массив" << endl;
- for (int i = 0; i < num; i++)
- {
- cout << a[i] << endl;
- }
- cout << "5 наименьших значений массива: ";
- for (int i = 0; i < 5; i++)
- {
- if (i == 4)
- cout << a[i];
- else
- cout << a[i] << ", ";
- }
- delete[] a;
- return 0;
- }
Add Comment
Please, Sign In to add comment