codeup_100000566_E

 我的解答:

#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; 
} 

总结:

  1. 输入格式: float用%f,double用%lf
  2. 输出格式都用%f
  3. 输出格式的占位控制:%x.yf,宽度占x位,其中小数部分y位
  4. 注意题目要求的输出格式
  5. 出现1.#j或-1.#j表示出现了除数为0
发布了36 篇原创文章 · 获赞 3 · 访问量 1264

猜你喜欢

转载自blog.csdn.net/Zen_Ivan/article/details/104973111