您的位置:首页 > 编程语言 > C语言/C++

求解一元二次方程的简单c语言程序

2012-04-22 12:16 134 查看
#include <math.h>
#include <stdio.h>
main()
{
double  a, b, c, disc, x1, x2;
do
{
printf("Input  a, b, c: ");//a、b、c分别为二次项一次项常数项系数。
scanf("%lf,%lf,%lf", &a, &b, &c);
disc = b*b - 4*a*c;
if (disc < 0)
printf("disc=%lf \n Input again!\n", disc);
} while (disc<0);
printf("*******the result*******\n");
x1 = (-b+sqrt(disc))/(2*a);
x2 = (-b-sqrt(disc))/(2*a);
printf("\nx1=%6.2lf\nx2=%6.2lf\n", x1, x2);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: