some one help me pls..
segmentation fault for merge_sort....:(
#include<stdlib.h>
#include<stdio.h>
void merge_sort(int [],int ,int );
void merge(int [],int ,int , int);
int main()
{
int i,n,a[25];
printf("enter the no of elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the element:");
scanf("%d",&a[i]);
}
merge_sort(a,0,n-1);
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
return 0;
}
void merge_sort(int a[],int p,int q)
{
if(p<q)
{
merge_sort(a,p,p+q/2);
merge_sort(a,(p+q/2)+1,q);
merge(a,p,p+q/2,q);
}
}
void merge(int a[],int low,int mid,int high)
{
int i,j[30],l,m,k,g;
l=low;
m=mid+1;
i=low;
while(l<=mid && m<=high)
{
if(a[l]<=a[m])
{
j[i]=a[l];
l++;
}
else
{
j[i]=a[m];
m++;
}
i++;
}
if(m>high)
{
for(g=l;g<=mid;g++)
{
j[i]=a[g];
i++;
}
}
else
{
for(g=m;g<=high;g++)
{
j[i]=a[g];
i++;
}
}
for(i=low;i<=high;i++)
{
a[i]=j[i];
}
}