I've tried a debugger and Catch and throw, though I confess I'm not comfortable with either. But I'm not able to find the cause of Floating Point Exception in my program. The weird thing is it runs perfect for numbers <= 35. Beyond that, it raises the exception. Where's the problem?
int fibo(int n)
{ if(n==0 || n==1)
return 1;
int p=1;
while(n>1)
p*=(n--);
return p;
}
int main()
{ int T;
int N, M;
cin>>T;
for(int i=0; i<T; i++)
{
cin>>N>>M;
int cnt=1;
int ones=N, twos=0;
if(ones==1 && M==1)
{ cout<<"CORRECT"<<endl;
continue;
}
else if(ones==1 && M!=1)
{ cout<<"INCORRECT"<<endl;
continue;
}
while(ones>=2)
{
ones-=2;
twos++;
cnt+= fibo(ones+twos)/( fibo(ones) * fibo(twos) );
}
cout<<cnt<<endl;
int tmp=0;
while(cnt>0)
{ if(cnt%2 == 1)
tmp++;
cnt/=2;
}
if( tmp==M )
cout<<"CORRECT"<<endl;
else
cout<<"INCORRECT"<<endl;
}
system("pause");
return 0;
}
Thanks a lot.