Code:
main()
{
/* Declare three integer arrays as follows */
int a[50], b[70], c[120];
/* Implement a function set_array_rand(int x[], int n)
and call it to generate the values in array a and b
randomly. */
set_array_rand(a, 50);
set_array_rand(b, 70);
/* Using the selection_sort(double x[], int n)
function we implemented in class, sort the elements in
a and b arrays. */
selection_sort(a, 50);
selection_sort(b, 70);
/* Implement a MERGE function and call it as follows
to merge the values in arrays a and b into array c
such that the values in c will be sorted after merging
*/
merge_sort(a, 50, b, 70, c, 120);
/* Print the values in array c */
print_array(c, 120);
}
void set_array_rand(int x[], int n)
{
/* Randomly generate elements of x array */
for(int i=0; i< n; i++)
x[i] = rand_int(30, 100);
}
int rand_int(int a,int b)
{
return rand()%(b-a+1) + a;
}
void selection_sort(int x[], int n)
{
/* YOUR CODE */
for (i=0; i<100; i++)
data[i] = (rand() % 100) + 30;
}
void merge_sort(int a[], int na, int b[], int nb, int c[],
int nc)
{
/* merge the values in a and b into c while keeping
the values sorted. For example, suppose we have the
following arrays a = { 3, 7, 9, 12} and b = {4, 5, 10}
When we merge these two arrays, we will get
c = {3, 4, 5, 7, 9, 10, 12} */
/* YOUR CODE */
int a[]={3, 7, 9, 12,};
int b[]={4,5,10}
int a, b, count;
for(a = 0; a < 12; i++){
count = 1;
for(b = 0; b < 10; j++){
if (x[a] == x[b]) count++;
}
printf(“%d %d \n”, x[a], count);
}
}
void print_array(int x[], int n)
{
/* YOUR CODE */
}