it hangs after inputting all the elements of the array in first for loop.
hangs? Are you sure... that's pretty good considering your merge code declares a pointer to an int:
int *x;
and never initializes it, then tries to jump to an offset (i
) past it:
x[i]=a[j];
Change your code to this:
int *x = malloc(n * sizeof(int));
and it should stop crashing/hanging whatever.
FYI, whenever you malloc()
you should free()
right now you have memory leaks.