C PROGRAM BEING USED: In the following code, how do I replace the Merge Sort code with the qsort() standard library function? The sorting function in the code should be utilizing the qsort() function and not the Merge Sort code. //include reuired headr files #include //this header is used for srand() and rand() functions #include //this header file is used for time() function #include //main() function int main() {     //declare array and variables     int a[100], number, i, j, temp;      // Use current time as      // seed for random generator     srand(time(0));     //create random number between 0 to 99 and assign to array      for(i = 1; i <=100; i++)         a[i]=rand() % 99 + 1;     //print source array which is not sorted     printf("Source Array:\n");      for(i = 1; i <= 100; i++)  {         //assign array value to n         int n=a[i];         //declare count variable and initialise to 0         int count=0;         //this loop counts numer of didig in number         while (n != 0)          {         n /= 10;     // n = n/10         ++count;         }         //if count is 1 then it append 0 at starting when printing         if(count==1)         {         printf("0%d ", a[i]);         }         //otherwise it print number         else         {             printf("%d ",a[i]);         }         //display 20 numbers in each line         if(i%20==0)         {             printf("\n");         }     }     //this is used for sorting using selection sort     //set i to first location and after each iteration increment the i     for(i = 1; i <= 100; i++) {         //set j to next of i value          //compare all next values in array with i value         for(j = i + 1; j <= 100; j++) {             //if a[i] value is greater than a[j] then swap the element             if(a[i] > a[j]) {                 temp = a[i];                 a[i] = a[j];                 a[j] = temp;             }         }     }     //print sorted array     printf("\nDestination array:\n");     for(i = 1; i <= 100; i++)  {        //assign array value to n         int n=a[i];         //declare count variable and initialise to 0         int count=0;         //this loop counts numer of didig in number         while (n != 0)          {         n /= 10;     // n = n/10         ++count;         }         //if count is 1 then it append 0 at starting when printing         if(count==1)         {         printf("0%d ", a[i]);         }         //otherwise it print number

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C PROGRAM BEING USED: In the following code, how do I replace the Merge Sort code with the qsort() standard library function? The sorting function in the code should be utilizing the qsort() function and not the Merge Sort code.

//include reuired headr files
#include <stdio.h>
//this header is used for srand() and rand() functions
#include <stdlib.h>
//this header file is used for time() function
#include <time.h>
//main() function
int main()
{
    //declare array and variables
    int a[100], number, i, j, temp;
     // Use current time as 
    // seed for random generator
    srand(time(0));
    //create random number between 0 to 99 and assign to array 
    for(i = 1; i <=100; i++)
        a[i]=rand() % 99 + 1;
    //print source array which is not sorted
    printf("Source Array:\n");
     for(i = 1; i <= 100; i++)  {
        //assign array value to n
        int n=a[i];
        //declare count variable and initialise to 0
        int count=0;
        //this loop counts numer of didig in number
        while (n != 0) 
        {
        n /= 10;     // n = n/10
        ++count;
        }
        //if count is 1 then it append 0 at starting when printing
        if(count==1)
        {
        printf("0%d ", a[i]);
        }
        //otherwise it print number
        else
        {
            printf("%d ",a[i]);
        }
        //display 20 numbers in each line
        if(i%20==0)
        {
            printf("\n");
        }
    }
    //this is used for sorting using selection sort
    //set i to first location and after each iteration increment the i
    for(i = 1; i <= 100; i++) {
        //set j to next of i value 
        //compare all next values in array with i value
        for(j = i + 1; j <= 100; j++) {
            //if a[i] value is greater than a[j] then swap the element
            if(a[i] > a[j]) {
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
    //print sorted array
    printf("\nDestination array:\n");
    for(i = 1; i <= 100; i++)  {
       //assign array value to n
        int n=a[i];
        //declare count variable and initialise to 0
        int count=0;
        //this loop counts numer of didig in number
        while (n != 0) 
        {
        n /= 10;     // n = n/10
        ++count;
        }
        //if count is 1 then it append 0 at starting when printing
        if(count==1)
        {
        printf("0%d ", a[i]);
        }
        //otherwise it print number
        else
        {
            printf("%d ",a[i]);
        }
        //display 20 numbers in each line
        if(i%20==0)
        {
            printf("\n");
        }
    }
    printf("\n");
    return 0;
}

 

The output of the program should look remarkably similar to the image output.

Source array:
05 82 43 80 54 50 14 03 01 90 09 52 68 90 53 44 76 59 50 35
08 41 89 04 25 48 50 59 45 64 40 89 45 93 57 39 84 87 86 11
32 78 26 11 59 31 48 10 25 24 04 48 52 52 45 62 30 11 99 45
72 31 52 38 44 06 73 42 22 38 39 87 08 24 24 42 35 43 57 29
31 12 54 51 76 86 87 18 35 23 27 80 94 07 92 04 01 14 91 53
Destination array:
01 01 03 04 04 04 05 06 07 08 08 09 10 11 11 11 12 14 14 18
22 23 24 24 24 25 25 26 27 29 30 31 31 31 32 35 35 35 38 38
39 39 40 41 42 42 43 43 44 44 45 45 45 45 48 48 48 50 50 50
51 52 52 52 52 53 53 54 54 57 57 59 59 59 62 64 68 72 73 76
76 78 80 80 82 84 86 86 87 87 87 89 89 90 90 91 92 93 94 99
Transcribed Image Text:Source array: 05 82 43 80 54 50 14 03 01 90 09 52 68 90 53 44 76 59 50 35 08 41 89 04 25 48 50 59 45 64 40 89 45 93 57 39 84 87 86 11 32 78 26 11 59 31 48 10 25 24 04 48 52 52 45 62 30 11 99 45 72 31 52 38 44 06 73 42 22 38 39 87 08 24 24 42 35 43 57 29 31 12 54 51 76 86 87 18 35 23 27 80 94 07 92 04 01 14 91 53 Destination array: 01 01 03 04 04 04 05 06 07 08 08 09 10 11 11 11 12 14 14 18 22 23 24 24 24 25 25 26 27 29 30 31 31 31 32 35 35 35 38 38 39 39 40 41 42 42 43 43 44 44 45 45 45 45 48 48 48 50 50 50 51 52 52 52 52 53 53 54 54 57 57 59 59 59 62 64 68 72 73 76 76 78 80 80 82 84 86 86 87 87 87 89 89 90 90 91 92 93 94 99
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education