If you don't know this problem it is here http://acm.uva.es/p/v1/100.html.

I don't know why my code is receiving wrong answer. It is right for the selected input. Also, I've done 1 1000000 and it doesn't seg fault on any numbers. Then I thought from the way that they worded it that they could give input out of order (swap function), but that didn't fix it. Why do they say it is wrong.

ThanksCode:/*@JUDGE_ID: 110101 100 C "3n+1"*/ #include <stdio.h> unsigned long int func(unsigned long int num); void swap(unsigned long int *tx,unsigned long int *ty); int main(void){ unsigned long x,y,z,max=0,temp; fflush(stdout); while(scanf("%lu %lu", &x,&y)==2){ if(x>y) swap(&x,&y); max = 0; for(z=x;z<=y;z++){ temp = func(z); if(temp>max) max = temp; } printf("%lu %lu %lu\n",x,y,max); } return 0; } void swap(unsigned long int *tx,unsigned long int *ty){ unsigned long int temp; temp = *tx; *tx = *ty; *ty = temp; } unsigned long int func(unsigned long int num){ if(num == 1){ return 1; } else if(num%2==0){ return 1 + func(num/2); } else{ return 1 + func(num*3+1); } }