scanf is collecting the wrong input

前端 未结 3 1513
花落未央
花落未央 2021-01-29 08:13
 #include 
 int main(void)
 {
      double c;
      scanf(\"%f\", &c);
      printf(\"%f\", c);
 }

This is an exerpt from a program

3条回答
  •  囚心锁ツ
    2021-01-29 08:21

    the outputTry %lf instead of %f

    #include
    
    int main()
    {
    double c;
    scanf("%lf",&c);
    printf("%lf",c);
    return 0;
    }
    

    What you've used is %f, which is used for a regular float datatype. since you've specified double , you need to use %lf , which is long float. it reads a double. hope this helps you.

提交回复
热议问题