一个OJ上的C语言题目,求方程的根,提交显示答案错误,帮忙看看
#include<stdio.h>#include<math.h>doublea,b,c;doubledeta;doublex1,x2;voidfun1(){x1=(-b...
#include <stdio.h>
#include <math.h>
double a,b,c;
double deta;
double x1,x2;
void fun1()
{
x1=(-b+sqrt(deta))/(2*a);
x2=(-b-sqrt(deta))/(2*a);
printf("x1=%.3lf x2=%.3lf\n",x1,x2);
}
void fun2()
{
double p,q;
p=-b/(2*a);
q=sqrt(-deta)/(2*a);
printf("x1=%.3lf+%.3lfi x2=%.3lf+%.3lfi\n",p,q,p,q);
}
main()
{
scanf("%lf%lf%lf",&a,&b,&c);
deta=b*b-4*a*c;
if(deta>=0)
fun1();
else
fun2();
} 展开
#include <math.h>
double a,b,c;
double deta;
double x1,x2;
void fun1()
{
x1=(-b+sqrt(deta))/(2*a);
x2=(-b-sqrt(deta))/(2*a);
printf("x1=%.3lf x2=%.3lf\n",x1,x2);
}
void fun2()
{
double p,q;
p=-b/(2*a);
q=sqrt(-deta)/(2*a);
printf("x1=%.3lf+%.3lfi x2=%.3lf+%.3lfi\n",p,q,p,q);
}
main()
{
scanf("%lf%lf%lf",&a,&b,&c);
deta=b*b-4*a*c;
if(deta>=0)
fun1();
else
fun2();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询