作者:夜色的静逸 | 来源:互联网 | 2023-10-10 11:06
- #include
-
- #include
- void main()
- {
- float a,b,c,disc,x1,x2;
- printf("请输入a,b,c,格式如:1,2,3:/n");
- scanf("%f,%f,%f",&a,&b,&c);
-
-
- if(fabs(a)<1e-6){
- printf("这个方程的两个根式是&#xff1a;%f,%f/n",-b/(2*a),-b/(2*a));
- }else{
- disc &#61; b*b-4*a*c;
- if(fabs(disc)<&#61;1e-6){
- x1 &#61; (-b&#43;sqrt(disc))/(2*a);
- x2 &#61; (-b-sqrt(disc))/(2*a);
-
- printf("这个方程有两个根是&#xff1a;%f,%f/n",x1,x2);
- }else{
- x1 &#61; -b/(2*a);
- x2 &#61; sqrt(-disc)/(2*a);
- printf("方程有虚根&#xff1a;%f,%f/n",x1,x2);
-
-
- }
- }
- }
代码不是很完善&#xff0c;在求虚根的时候不知道怎么做的。所以就不好了&#xff01;