|
发表于 2016-7-19 22:42:41
|
显示全部楼层
- #include <stdio.h>
- #include <math.h>
- float x1,x2,k,i,j;
- void f1 (float x ,float y);
- void f2 (float x ,float y);
- void f3 (float x ,float y);
- int main ()
- {
- float a,b,c;
- printf ("请输入三个数字,以逗号隔开:\n");
- scanf ("%f,%f,%f",&a,&b,&c);
- k=b*b-4*a*c;
- printf ("方程的根为:\n");
- if (k>0)
- {
- f1 (a,b);
- printf("x1=%f\tx2=%f\n", x1,x2);
- }
-
- else if (k==0)
- {
- f2 (a,b);
- printf("x1=%f\tx2=%f\n", x1,x2);
- }
-
- else
- {
- f3 (a,b);
- printf("x1=%f+%fi\tx2=%f-%fi\n", i,j,i,j);
- }
-
- return 0;
- }
- void f1 (float x ,float y)
- {
- x1=(-y+sqrt(k))/(2*x);
- x2=(-y-sqrt(k))/(2*x);
- }
- void f2 (float x ,float y)
- {
-
- x1=-y/(2*x);
- x2=-y/(2*x);
- }
- void f3 (float x ,float y)
- {
- i=-y/(2*x);
- j=sqrt(-k)/(2*x);
- }
复制代码
关键是scanf后面要用%f而不是%lf 输入时加上小数点。
C:\Users\Administrator\Desktop |
评分
-
查看全部评分
|