Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are a lucky lucky man. This won't solve the general problem of <code>long double</code> on MinGW, but I'll explain what is happening to your problem. Now, in a far far day when you'll be able to upvote, I want your upvote. :-) (but I don't want this to be marked as the correct response. It's the response to what you need, but not to what you asked (the general problem in your title <code>scanf not taking in long double</code>) ).</p> <p>First, the solution: use <code>float</code>. Use <code>%f</code> in <code>scanf</code>/<code>printf</code>. The results comes perfectly equal to the ones given as the solution in your site. As a sidenote, if you want to <code>printf</code> with some decimals, do as it's showed in the last printf: <code>%.10f</code> will print 10 decimals after the decimal separator.</p> <p>Second: why you had a problem with <code>double</code>s: the <code>res=sqrt()</code> calculates a square root. Using <code>float</code>s, <code>l*l+r*r-2*cosa*l*r</code> == 0.0, using <code>double</code>s it's -1.0781242565371940e-010, so something near zero BUT NEGATIVE!!! So the <code>sqrt(-something)</code> is <code>NaN</code> (Not a Number) a special value of <code>double/float</code>. You can check if a number is <code>NaN</code> by doing <code>res != res</code>. This because <code>NaN != NaN</code> (but note that this isn't guaranteed by older C standards, but in many compilers on Intel platform do it. <a href="http://www.gnu.org/s/hello/manual/libc/Infinity-and-NaN.html" rel="nofollow">http://www.gnu.org/s/hello/manual/libc/Infinity-and-NaN.html</a>). And this explains why the <code>printf</code> printed something like <code>-1.#IO</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload