STATUES-why segmentation fault

#include<stdio.h>
#define SWAP(x,y,t)(t=x,x=y,y=t)
int main()
{
int x,i,sum,p,n,a,j,k,temp,m;
while(1)
{
sum=0;
m=0;
scanf("%d",&n);
if(n==0)
exit(0);
a=(int
)malloc(nsizeof(int));
for(i=0;i<n;i++)
{
scanf("%d",a+i);
sum=sum+(
(a+i));
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(((a+j))<((a+i)))
SWAP(((a+i)),((a+j)),temp);
//for(i=0;i<n;i++)
//sum=sum+((a+i));
p=sum/n;
for(i=0;i<n;i++)
if((
(a+i))==p)
{
x=i;
j=x+1;
}
for(k=0;k<x;k++)
{
while(((a+k))!=p)
{
if((
(a+j))>p)
{
((a+j))–;
m++;
(
(a+k))++;
}
else j++;
}
}
printf("\n %d",m);
free(a);
}

}

what change did u made?? kunal361

add “#include <stdlib.h>” as “malloc” and “exit” are defined in this header file only

i tried this…bt the code still gives segmentation fault

//