#include <stdio.h>#include<math.h>intMain () {DoubleA, B, C, disc, X1, x2, p, q, I; Do{scanf_s ("A=%LF,B=%LF,C=%LF", &a, &b, &c); I= B*b-4* * *C; } while(i<0); printf ("Enter the correct"); Disc= B*b-4* * *C; P=-B/(2*a); Q= sqrt (disc)/(2*a); X1= p + q, x2 = P-Q; printf ("x1=%5.2f\nx2=%5.2f\n", x1, x2); return 0;}
In the group of people asked this example, calculated as a two-time equation, scanf () can not be used in vs2015, so I changed it to scanf_s ().
At the time I thought it entered:
A=1,b=2,c=3
does not satisfy its input correct condition, so must enter a=?,b=?,c=? These, however, can not continue to input, press other keys without any reaction, someone reply with fflush (stdin);
#include <stdio.h>#include<math.h>intMain () {DoubleA, B, C, disc, X1, x2, p, q, I; Do{fflush (stdin); scanf_s ("A=%LF,B=%LF,C=%LF", &a, &b, &c); I= B*b-4* * *C; } while(i<0); printf ("Enter the correct"); Disc= B*b-4* * *C; P=-B/(2*a); Q= sqrt (disc)/(2*a); X1= p + q, x2 = P-Q; printf ("x1=%5.2f\nx2=%5.2f\n", x1, x2); return 0;}
However, on my vs2015 still can not run, then I go to Baidu query.
The second loop cannot be entered because of the problem of the input buffer, after reading a number or character immediately after the read, should clear the input buffer, and fflush (stdin) can not run in vs2015, mainly because the function function is: empty input buffer, To ensure that the subsequent data reads are not affected. Note, however, that this function applies only to some compilers, such as VC6, and not all compilers support this function. The most appropriate practice is to add rewind (stdin).
#include <stdio.h>#include<math.h>intMain () {DoubleA, B, C, disc, X1, x2, p, q, I; Do{rewind (stdin); scanf_s ("A=%LF,B=%LF,C=%LF", &a, &b, &c); I= B*b-4* * *C; } while(i<0); printf ("Enter the correct"); Disc= B*b-4* * *C; P=-B/(2*a); Q= sqrt (disc)/(2*a); X1= p + q, x2 = P-Q; printf ("x1=%5.2f\nx2=%5.2f\n", x1, x2); return 0;}
Or output some of the following before reading:
#include <stdio.h>#include<math.h>intMain () {DoubleA, B, C, disc, X1, x2, p, q, I; Do{printf ("input A,b,c:"); scanf_s ("%LF%LF%LF", &a, &b, &c); I= B*b-4* * *C; } while(i<0); printf ("Enter the correct"); Disc= B*b-4* * *C; P=-B/(2*a); Q= sqrt (disc)/(2*a); X1= p + q, x2 = P-Q; printf ("x1=%5.2f\nx2=%5.2f\n", x1, x2); return 0;}
Fflush (stdin) and Rewind (stdin)