Note that there are some explanatory texts on larger screens.

plurals
  1. POscanf not taking in long double
    primarykey
    data
    text
    <p>i have problem with scanf not reading long double in the code below:</p> <p>(please excuse my poor English)</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdlib&gt; #include &lt;math.h&gt; using namespace std; int main() { int n; scanf("%d",&amp;n); long double a,b,c,ha,hb,hc,ma,cosa,r,l,res,area; for (int i=0;i&lt;n;i++) { scanf("%Lf %Lf %Lf %Lf",&amp;a,&amp;ha,&amp;hb,&amp;hc);//this is where the problem lies, //i need to read 4 long double a,ha,hb,hc printf("%Lf %Lf %Lf %Lf\n",a,ha,hb,hc);//but it returned wrong answer so //i used printf to check, ps: the code works with float but not with double or //long double ha*=3;hb*=3;hc*=3; c=(a*ha)/hc; b=(a*ha)/hb; ma=sqrt(0.5*b*b+0.5*c*c-0.25*a*a); cosa=ha/ma; r=(2*ma)/3; l=b*(b-sqrt(a*a-hb*hb))/ha; res=sqrt(l*l+r*r-2*cosa*l*r); area=a*ha/2; printf("%.3Lf %.3Lf\n",area,res); } system("PAUSE"); return 0;} } </code></pre> <p><em><strong>here's the input:</em></strong></p> <pre><code>2 3.0 0.8660254038 0.8660254038 0.8660254038 657.8256599140 151.6154399062 213.5392629932 139.4878846649 </code></pre> <p><em><strong>and here what's show in the command line:</em></strong></p> <pre><code>2 3.0 0.8660254038 0.8660254038 0.8660254038 3.000000 -4824911833695204400000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000.000000 284622047019579100000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000.0 00000 0.866025 -2.000 0.000 657.8256599140 151.6154399062 213.5392629932 139.4878846649 657.825660 -0.000000 28969688850499604000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000.000000 213.539263 -2.000 0.000 Press any key to continue . . . </code></pre> <p><em><strong>I want to know why scanf won't take in long double in the code and how to fix it.</em></strong></p> <p><em>Thanks in advance!</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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