#include <stdio.h>
void swap(int* a, int* b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void sort(int arr[], int n)
{
int i, j, min;
for (i = 0; i < n - 1; i++) {
min = i;
for (j = i + 1; j < n; j++)
if (arr[j] < arr[min])
min = j;
swap(&arr[min], &arr[i]);
}
}
void display(int arr[], int n)
{
int i;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}
int main()
{
int arr[] = { 12, 7, 14, 11, 91 };
int n = sizeof(arr) / sizeof(arr[0]);
printf("Original answer sheets: \n");
display(arr, n);
sort(arr, n);
printf("\nSorted Answer sheets: \n");
display(arr, n);
return 0;
}
Comments
Leave a comment