Hi :-)
I need to write a function that will merge the content of two sorted arrays of type double values. The function should not assume that both its input parameter arrays are the same length.
Here is my program so far - I know there is alot of errors and mistakes, but I would be happy if somebody could point some of them out for me:
Code:
#include<stdio.h>
void merge(int firstArray[],int secondArray[],int size)
{
int mergedArray[size],i=0,j=0,k=0;
while(i<size||j<size)
{
if(i==size)
{
while(j<size)
{
mergedArray[k]=secondArray[j];
j++;
}
}
if(j==size)
{
while(i<size)
{
mergedArray[k]=secondArray[i];
i++;
}
}
if(firstArray[i]>secondArray[j])
{
mergedArray[k]=secondArray[j];
j++;
}
else
{
mergedArray[k]=firstArray[i];
i++;
}
k++;
}
}
int main(void){
int firstArray[sizeFirst], secondArray[sizeSecond], mergedArray[size], i, j, k, size, sizeFirst, sizeSecond;
double firstArray[a], secondArray[b];
printf("Enter the size of the first array:\n");
scanf("%d", &sizeFirst);
printf("Enter %d numbers seperated by blanks or <return>s first array\n", sizeFirst);
for (i=0; i<size; ++i)
scanf("%lf", &firstArray[a]);
printf("Enter the size of the second array:\n");
scanf("%d", &sizeSecond);
printf("Enter %d numbers seperated by blanks or <return>s second array\n", sizeSecond);
for (i=0; i<size; ++i)
scanf("%lf", &secondArray[b]);
merge (firstArray, secondArray, mergedArray);
printf("The merged array is: %d\n", mergedArray);
return (0);
}
/Fedryan