谁给我写个解1元2次方程的C语言代码

来源:百度知道 编辑:UC知道 时间:2024/06/03 19:36:09
方程是 X的平方 加 X 减 2 等于 0
要求能编译的。。能编译就给分~

注意要C语言的~~不要C++
VB也可以

#include "stdio.h"
#include <math.h>
void main()
{
double a=1,b=1,c=-2;
double x1,x2;
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("x1=%.2f, x2=%.2f",x1,x2);

}

用函数,你真狠。

markzong的程序编译通过,并且得到正确结果