From 53581f288876c74725af64ebb02dc3c5a21a1aed Mon Sep 17 00:00:00 2001 From: Misha Date: Thu, 2 Oct 2025 18:23:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?/=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task1.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 task1.cpp diff --git a/task1.cpp b/task1.cpp new file mode 100644 index 0000000..cb9d432 --- /dev/null +++ b/task1.cpp @@ -0,0 +1,50 @@ +#include +using namespace std; + +void sortArr(int* p, int n) { + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < n - i - 1; j++) { + if (p[j] > p[j + 1]) { + int t = p[j]; + p[j] = p[j + 1]; + p[j + 1] = t; + } + } + } +} + +void printArr(int* p, int n) { + for (int i = 0; i < n; i++) { + cout << p[i] << " "; + } + cout << "\n"; +} + +int main() { + srand(time(0)); + int n; + + cout << "Enter N: "; + cin >> n; + + int* a = new int[n]; + + for (int i = 0; i < n; i++) { + a[i] = rand() % 101 - 50; + } + + cout << "\nOriginal array:\n"; + printArr(a, n); + + sortArr(a, n); + + cout << "\nSorted array:\n"; + printArr(a, n); + + cout << "\nArray without first and last elements:\n"; + printArr(a + 1, n - 2); + + delete[] a; + return 0; + +}