Answer to Question #241625 in C for Ram

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.
1
Expert's answer
2021-09-24T18:58:01-0400


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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS