WA- where does floating point error occur?

Revision en1, by vsanjay_nitdgp, 2016-02-10 20:19:46

Recently,I solved a problem.

This is one of my step in my solution:

ans=ans-(2*b*c[n]);

ans is double variable,b is integer,c[n] is double; my answer was judged wrong.

when i changed the step to

double p=2*b*c[i];
ans=ans-p;

My solution got ACCEPTED.Could anyone say,why this occur,so that it would be very helpful for future problems of this kind.

Thanks.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English vsanjay_nitdgp 2016-02-10 20:19:46 464 Initial revision (published)