我的解答:
#include <stdio.h>
#include <math.h>
int main () {
double a, b, c;
double r1, r2;
scanf("%lf%lf%lf", &a, &b, &c); //%lf代表双精度浮点型数据(double)
//printf("a = %f\n", a);
//printf("b = %f\n", b);
//printf("c = %f\n", c);
r1 = (-b+sqrt(b*b-4*a*c))/(2*a);
r2 = (-b-sqrt(b*b-4*a*c))/(2*a);
printf("r1=%7.2f\n", r1); //%7.2f:宽度占x位,其中小数部分y位
printf("r2=%7.2f", r2); //注意题目要求的输出格式
return 0;
}
总结:
- 输入格式: float用%f,double用%lf
- 输出格式都用%f
- 输出格式的占位控制:%x.yf,宽度占x位,其中小数部分y位
- 注意题目要求的输出格式
- 出现1.#j或-1.#j表示出现了除数为0