PTA上如果遇上了警告:ignoring return value of scanf,declared with attribute 该怎么解决
你就int res = scanf("%f%f%f",&a,&b,&c);看看还警不警告
修改如下,供参考:
#include <stdio.h>
#include <math.h>
int main()
{
int ret;
float a, b, c, x1, x2, d, p;
ret = scanf("%f%f%f", &a, &b, &c);
if (ret == 3) {
d = b * b - 4 * a * c;
if (d < 0)
printf("此方程无解");
else {
p = sqrt(d);
x1 = (-b + p) / (2 * a);
x2 = (-b - p) / (2 * a);
printf("%.2f,%.2f", x1, x2);
}
}
return 0;
}