I actually figured out my problem, took a while but finally got my code to work. Now I just have to figure out how to implement the third array so no repeats are stored in the array. Not really sure how to do this part yet.
Code:
#include <stdio.h>
#include<time.h> // for time()
#include<stdlib.h> //for rand()
void sortArray(int array[], int);
void sortArrayb(int arrayb[], int);
void merge(int array[], int x, int arrayb[], int y, int sorted[]);
int main()
{
int x,y,c;
int array[100];
int arrayb[50];
int sorted[150];
srand(time(NULL)); //random number generator
printf("Enter number of elements in the first array:\n");
scanf("%d", &x);
printf("Enter number of elements in the second array:\n");
scanf("%d", &y);
sortArray(array, x);
sortArrayb(arrayb, y);
merge(array, x, arrayb, y, sorted);
printf("Sorted array:\n");
for (c = 0; c < x + y; c++)
{
printf("%d\n", sorted[c]);
}
return 0;
}
void sortArray(int array[], int x)
{
int c, d, position, swap;
for ( c = 0 ; c < x ; c++ )
array[c] = rand()%100; // storing a random number between 0 and 100
for ( c = 0 ; c < ( x - 1 ) ; c++ )
{
position = c;
for ( d = c + 1 ; d < x ; d++ )
{
if (array[position] > array[d])
position = d;
}
if ( position != c )
{
swap = array[c];
array[c] = array[position];
array[position] = swap;
}
}
//printf("Sorted list in ascending order:\n");
//for (c = 0; c < x; c++)
//printf("%d\n", array[c]);
}
void sortArrayb(int arrayb[], int y)
{
int e, f, pos, change;
for (e = 0; e < y; e++)
arrayb[e] = rand()%50; // storing a random number between 0 and 100
for (e = 0; e < (y - 1); e++)
{
pos = e;
for (f = e + 1; f < y; f++)
{
if (arrayb[pos] > arrayb[f])
pos = f;
}
if (pos != e)
{
change = arrayb[e];
arrayb[e] = arrayb[pos];
arrayb[pos] = change;
}
}
}
void merge(int array[], int x, int arrayb[], int y, int sorted[])
{
int i, j, k;
j = k = 0;
for (i = 0; i < x + y;)
{
if (j < x && k < y)
{
if (array[j] < arrayb[k])
{
sorted[i] = array[j];
j++;
}
else
{
sorted[i] = arrayb[k];
k++;
}
i++;
}
else if (j == x)
{
for (; i < x + y;)
{
sorted[i] = arrayb[k];
k++;
i++;
}
}
else
{
for (; i < x + y;)
{
sorted[i] = array[j];
j++;
i++;
}
}
}
}