编写函数求一元二次方程的根,并在main主函数中调用该函数 用c++编写

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 10:54:37
编写函数求一元二次方程的根,并在main主函数中调用该函数 用c++编写

编写函数求一元二次方程的根,并在main主函数中调用该函数 用c++编写
编写函数求一元二次方程的根,并在main主函数中调用该函数 用c++编写

编写函数求一元二次方程的根,并在main主函数中调用该函数 用c++编写
#include
#include
void b1 ()
{
float l,s,k;
int a,b,c,h;
printf ("\n");
printf("\n");
printf("输入a,b,c的值\n");
printf("\n");
scanf("%d%d%d",&a,&b,&c);
printf("a=%d b=%d c=%d\n",a,b,c);
printf("\n");
h=b*b-4*a*c;printf("%d\n",h);
l=sqrt(h);printf("%f\n",l);
s=( -b+l )/2*a;
k=( -b-l )/2*a;
if (h>0)
printf ("这个方程有两个根为:x1=%.2f x2=%.2f\n",s,k);
else
if (h=0)
printf ("这个方程有一个根为:x=%.2f\n",s);
else
printf ("这个方程没有根\n");
}
int main()
{

b1();
}