can anyone please tell me what is wrong with dis code.....i am getting a segmentation fault even though it has been compiled successfully(in a unix system):
#include<stdio.h>
int low,high,mid;
void msort(int a[],int low,int high);
void merge(int a[],int low,int high,int mid);
int main()
{
int a[10];
int count;
for(count=0;count<10;count++)
{
printf("Enter element number %d\n",count+1);
scanf("%d" , &a[count]);
}
low=a[0];
high=a[9];
msort(a,low,high);
for(count=0;count<10;count++)
{
printf("%d\n" ,a[count]);
}
}
void msort(int a[],int low,int high)
{
int mid;
if(low<high)
{
mid=(low+high)/2;
msort(a,low,mid);
msort(a,mid+1,high);
merge(a,low,high,mid);
}
}
void merge(int a[],int low,int high,int mid)
{
int b[50];
int i,j,k;
i=low;
j=mid+1;
k=low;
while((i<=mid)&&(j<=high))
{
if(a[i]<a[j])
{
b[k]=a[i];
i++;
k++;
}
else
{
b[k]=a[j];
j++;
k++;
}
}
while(i<=mid)
{
b[k]=a[i];
i++;
}
while(j<=high)
{
b[k]=a[j];
j++;
}
for(i=0;i<high;i++)
{
a[i]=b[i];
}
}