what i did wrong so that i got sigsegv error?

#include<stdio.h>
int main()
{
unsigned short int t;
short int n;
int i,j;
scanf("%hd",&t);
while(t–)
{
scanf("%hd",&n);
long int a[n];
int ar[100000];
for(i=0;i<n;i++)
{
scanf("%ld",&a[i]);
}
// for(i=0;i<n;i++)
// printf("%d",a[i]);
// printf("\n");
int k=0,c=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i!=j)
{
ar[k]=a[i]-a[j];
k++;
c++;
}
}
}
// for(i=0;i<c;i++)
// printf("%d\t",ar[i]);
for(i=0;i<c;i++)
{
if(ar[i]<0)
ar[i]=ar[i]*(-1);
}
int min=ar[0];
for(i=1;i<c;i++)
{
if(ar[i]<min)
{
min=ar[i];
}
}
printf("%d",min);

	}
	return 0;
}

@rohity123

Given that,

2 ≤ N ≤ 5000

which means the value of k in your code will range as n^2-n,

`i.e. 4-2 ≤ k ≤ 25000000-5000`

And you used “int ar[100000]”,and so ar[k] will account to SIGSEGV(Invalid Memory Reference).

//