Загрузить файлы в «/»
This commit is contained in:
50
task1.cpp
Normal file
50
task1.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include <iostream>
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user