#include #include // Sort an array using Selection Sort void printArray(int a[], int n) { int i; printf("\nIndex i: "); for(i=0; i< n; i++) printf("%2d, ", i); printf("\nElement a[i]: "); for(i=0; i< n; i++) printf("%2d, ", a[i]); printf("\n\n"); } #define N 6 int main() { int a[N]= { 23, 78, 45, 8, 32, 56}; int i,j; // Print the unsorted array printArray(a, N); // Sort the array using Selection Sort int minIndex; for(i=0; i < N-1; i++) { // find the minimum element in the unsorted part of the array minIndex=i; for(j=i+1; j < N; j++) if(a[j] < a[minIndex]) minIndex = j; // Swap a[i] with the smallest element int temp = a[i]; a[i] = a[minIndex]; a[minIndex] = temp; } // Print the sorted array printArray(a,N); system("pause"); }