I wrote this program for insertion sort.I compiled the source file in xubuntu terminal.But when I try to run a.out executable....terminal showing "segmentation fault".I don't about segmentation fault..when segmentation fault occurs...what is the thing in the source file that is causing segmentation fault...
Thanks in advance......
#include<stdio.h>
main(){
int i,j,n,key;
int a[n];
printf("Enter size:");
scanf("%d",&n);
printf("\n Enter elements:separate each by space\n");
for(j=0;j<n;j++)
scanf("%d ",&a[j]);
for(j=1;j<=n-1;j++){
key=a[j];
i=j-1;
while((i>=0)&&(a[i]>key)){
a[i+1]=a[i];
i=i-1;
}
a[i+1]=key;
}
for(j=0;j<=n-1;j++)
printf("%d ",a[j]);
}