Selection Sort:
#include <iostream>
using namespace std;
int main() {
int size;
cout<<"enter size of array";
cin>>size;
int arr[size];
cout<<"enter values of array"<<endl;
for (int i = 0; i < size; i++) {
cin>> arr[i];
}
cout << endl;
cout << "Original array: ";
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl;
// Selection sort
for (int i = 0; i < size - 1; ++i) {
int minIndex = i;
// Find the minimum element in the unsorted part of the array
for (int j = i + 1; j < size; ++j) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
// Swap the found minimum element with the first element
int temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
}
cout << "Sorted array: ";
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout <<endl;
return 0;}