Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help me with step by step and correct output, thanks using C program Write a fun

ID: 3688873 • Letter: H

Question

help me with step by step and correct output, thanks using C program

Write a function for Bubble Sort that sorts the array and produces a trace of how the array is being sorted. Each time the array is modified, it's printed out so the user can observe how the array is changing. Your code should have: A function PrintArray that prints the whole array A function BubbleSort that sorts the array and calls PrintArray The sample output below shows how the Bubble Sort modifies the array to make it sorted. The last two passes don't print anything since they don't perform any changes on the array.

Explanation / Answer

#include<stdio.h>

#include<conio.h>

void bubble_sort(int[], int);

void main() {

   int arr[30], num, i;

   printf(" Enter no of elements :");

   scanf("%d", &num);

   printf(" Enter array elements :");

   for (i = 0; i < num; i++)

      scanf("%d", &arr[i]);

   bubble_sort(arr, num);

   getch();

}

void bubble_sort(int iarr[], int num) {

   int i, j, k, temp;

   printf(" Unsorted Data:");

   for (k = 0; k < num; k++) {

      printf("%5d", iarr[k]);

   }

   for (i = 1; i < num; i++) {

      for (j = 0; j < num - 1; j++) {

         if (iarr[j] > iarr[j + 1]) {

            temp = iarr[j];

            iarr[j] = iarr[j + 1];

            iarr[j + 1] = temp;

         }

      }

      printf(" After pass %d : ", i);

      for (k = 0; k < num; k++) {

         printf("%5d", iarr[k]);

      }

   }

}