本帖最后由 Krant5 于 2016-7-19 19:01 编辑 #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);
}
|