Question #241625

Due to a rush at the end of the exam, Professor could not arrange the answer sheets in the
sequence as desired. However, he mentioned the correct location of each answer sheet with it.
Now, Professor wants all the answer sheets in the desired sequence.

Expert's answer



#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;
}

LATEST TUTORIALS
APPROVED BY CLIENTS