https://www.cnblogs.com/longhai3/longhai

C语言>>一元二次方程

Posted on 2022-02-12 18:28  凡是过去,皆为序曲  阅读(11)  评论(0编辑  收藏  举报

 

#include<stdio.h>
#include<math.h>
int main()
{
printf("解一元二次方程ax^2+bx+c=0\n");
double a,b,c,x1,x2,m1,m2,n1,n2;
printf("请输入a,b,c\n");
scanf("%lf%lf%lf",&a,&b,&c);
if((b*b-4*a*c>0)||(b*b-4*a*c==0))
{
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("实根\n%f \n%f",x1,x2);
}
else
{
m1=-b/(2*a);
m2=sqrt(4*a*c-b*b)/(2*a);
n1=-b/(2*a);
n2=sqrt(4*a*c-b*b)/(2*a);
printf("复根\n");
printf("x1=%lf+%lf*i\n",m1,m2);
printf("x2=%lf-%lf*i",n1,n2);
}
return 0;
}

随心,随记

https://www.cnblogs.com/w1hg/331817