Lead game

Why this code show SIGSEGV error but this code work fine in dev c?..please reply asap

#include <stdio.h>
#include <math.h>
int main()
{
int n,s[100],i[100],a[10],j,m,W;
scanf("%d",&n);
for(j=0;j<n;j++)
{
scanf("%d%d",&s[j],&i[j]);
a[j]=abs(s[j]-i[j]);
}
m=max(a,n);
for(j=0;j<n;j++)
{
if(a[j]==m)
break;
}
if(s[j]>i[j])
W=1;
else
W=2;
printf("%d %d",W,m);

return 0;
}
int max(int a[],int n)
{
int m,i;
m=a[0];
for(i=0;i<n;i++)
{
if(m<a[i])
m=a[i];
}
return m;
}

//