What purporse does the following code serves int main() { int array[] = {5, 3,…

20252024

What purporse does the following code serves

int main()

{

int array[] = {5, 3, 1, 9, 8, 2, 4, 7};

int size = sizeof(array)/sizeof(array[0]);

int i, j, min_idx,temp;

for (i = 0; i < size-1; i++)

{

min_idx = i;

for (j = i+1; j < size; j++)

{

if (array[j] < array[min_idx])

min_idx = j;

}

temp = array[min_idx];

array[min_idx] = array[i];

array[i] = temp;}

  1. A.

    Finds some specific element in the array

  2. B.

    Sort the elements of array

  3. C.

    Find the smallest element in the array

  4. D.

    None of the above

Attempted by 172 students.

Show answer & explanation

Correct answer: B

Following code snippet is the code of selection sort, which compares each element of the array with all the other elements and arrange them in a specific order

Explore the full course: Accenture Preparation