发布网友 发布时间:2023-03-13 16:58
共2个回答
热心网友 时间:2023-10-21 10:03
#include <stdio.h>
#include <math.h>
float x1,x2;
main()
{
void f1(float a1,float a2,float a3);
void f2(float b1,float b2,float b3);
void f3(float c1,float c2,float c3);
float a,b,c,t;
printf("Input a=,b=,c=\n");
scanf("a=%f,b=%f,c=%f",&a,&b,&c); //输入格式为a=1,b=5,c=6;
t = b*b - 4*a*c;
if(fabs(t)<=1e-6) // 判断t==0 的情况。
f1(a,b,c);
else
{
if(t>1e-6) // t>0的情况
f2(a,b,c);
else
f3(a,b,c);
}
}
void f1(float a1,float a2,float a3)
{
x1 = x2 = -a2/(2*a1);
printf("x1 = x2 = %f\n",x1);
}
void f2(float b1,float b2,float b3)
{
float disc;
disc = sqrt(b2*b2-4*b1*b3);
x1 = (-b2 + disc)/(2*b1);
x2 = (-b2 - disc)/(2*b1);
printf("x1 = %f\nx2 = %f\n",x1,x2);
}
void f3(float c1,float c2,float c3)
{
float disc,t1,t2;
disc = sqrt(4*c3*c1-c2*c2);
t1 = -c2/(2*c1);
t2 = disc/(2*c1);
printf("x1 = %f + %fi\n",t1,t2);
printf("x2 = %f - %fi\n",t1,t2);
}
热心网友 时间:2023-10-21 10:03
#include<stdio.h>