I have written an algo for prime generator and it works fine in my compiler. But when i submit it in spoj it says the following error : "SIGSEGV".
This is my code:
include
include
int main(){
long int m,n,c1,c2,c3;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&m,&n);
//create prime list
short int *prime;
prime = (short int*)malloc((n-m)*sizeof(short int));
int c1, c2, c3;
//fill list with 0 - prime
for(c1 = 2; c1 <= n; c1++){
prime[c1] = 1;
}
//set 1 and 0 as not prime
prime[0]=0;
prime[1]=0;
//find primes then eliminate their multiples (0 = prime, 1 = composite)
for(c2 = 2;c2 <= (int)sqrt(n)+1;c2++){
if(prime[c2] == 1){
c1=c2;
for(c3 = 2*c1;c3 <= n+1; c3 = c3+c1){
prime[c3] = 0;
}
}
}
//print primes
for(c1 = m; c1 <=n; c1++){
if(prime[c1]) printf("%i\n",c1);
}
}
getch();
return 0;
}
Please tell me where I m going wrong.
Thanks in advance 