Created
December 18, 2024 21:23
-
-
Save vlaleli/0099474b3d8c0e20da563fdf9aaef47c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() { | |
| const int SIZE = 10; | |
| int arr[SIZE]; | |
| cout << "Enter " << SIZE << " array elements:" << endl; | |
| for (int i = 0; i < SIZE; i++) { | |
| cin >> arr[i]; | |
| } | |
| for (int i = 0; i < SIZE / 2 - 1; i++) { | |
| int minIndex = i; | |
| for (int j = i + 1; j < SIZE / 2; j++) { | |
| if (arr[j] < arr[minIndex]) { | |
| minIndex = j; | |
| } | |
| } | |
| int temp = arr[i]; | |
| arr[i] = arr[minIndex]; | |
| arr[minIndex] = temp; | |
| } | |
| cout << "Array after sorting the first half:" << endl; | |
| for (int i = 0; i < SIZE; i++) { | |
| cout << arr[i] << " "; | |
| } | |
| cout << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment