|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 扶风之木 于 2022-6-6 22:10 编辑
原题如图:https://s1.ax1x.com/2022/06/06/XBpH10.png
- #include<stdio.h>
- #include<math.h>
- int main()//解一元二次方程
- {
- float a, b, c,t,x1,x2;
- printf("Please input a,b,c:");
- scanf_s("%lf,%lf,%lf",&a, &b, &c);
- t = b * b - 4 * a * c;
- if (t > 0)
- {
- x1 = -b + sqrt(t) / 2 * a, x2 = -b - sqrt(t) / 2 * a;
- printf("%f,%f", x1, x2);
- else if (t == 0)
- {
- x1 = x2 = -b / 2 * a; printf("%f,%f", x1, x2);
- }
- else printf("方程无解");
- }
- }
复制代码
- #include <stdio.h>
- #include <math.h>
-
- int main()
- {
- float a,b,c,x1,x2,d;
- printf("Please input a,b,c:");
- scanf("%f %f %f",&a,&b,&c);
- if(a!=0)
- {
- d=sqrt(b*b-4*a*c);
- x1=(-b+d)/(2*a);
- x2=(-b-d)/(2*a);
- if(x1<x2)
- printf("%0.2f %0.2f\n",x2,x1);
- else
- printf("%0.2f %0.2f\n",x1,x2);
- }
- return 0;
- }
复制代码
|
|