title: Why you mustn't write scanf("%.2lf", &a) in C?
body: <p>My friend have just started learning programming. He showed me his code and asked why it return some weird number. After taking a look at it, I saw that he was using <strong>scanf("%.2lf", &amp;a)</strong> to take input, and by habit, I try to change it to normal. Then he asked me why it has some strange output. After googling around I still haven't find the answer.</p>
  
  <p>Can anybody tell me why it doesn't work?</p>
  
  <p>Thank you in advance and sorry for the long irrelevant story as well as my bad English.</p>
  
  <p>Edit: added code below </p>
  
  <pre><code>    int main()
      {
          double a,b,c,delta;
          printf("Nhap vao 3 so thuc a,b,c: \n");
          scanf("%.2lf %.2lf %.2lf",&amp;a,&amp;b,&amp;c);
          if(a == 0 &amp;&amp; b == 0 &amp;&amp; c == 0) printf("Phuong trinh co vo so nghiem");
          else if(a == 0 &amp;&amp; b == 0 &amp;&amp; c != 0) printf("Phuong trinh vo nghiem");
          else if(a == 0 &amp;&amp; b != 0) printf("Phuong trinh co 1 nghiem la: %.2lf",-c/b);
          else if(a != 0)
          {
              delta=b*b-4*a*c;
              if(delta&lt;0) printf("Phuong trinh vo nghiem");
              else if(delta == 0) printf("Phuong trinh co nghiem kep: %.2lf",-b/(2*a));
              else if(delta &gt; 0) printf("Phuong trinh co 2 nghiem la:%.2lf, %.2lf",-(b-sqrt(delta))/(4*a),-(b+sqrt(delta))/(4*a));
          }
          return 0;
      }
  </code></pre>