a*x*x+b*x+c=0 的C语言 的篇写

来源:百度知道 编辑:UC知道 时间:2024/05/16 23:59:14

#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c;
double m;
double x1,x2;
printf("please insert a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
m=b*b-4*a*c;
if (m<0)
printf("the number is wrong,please insert again:");
else
x1=(-b+sqrt(m))/2*a;
x2=(-b-sqrt(m))/2*a;
printf("the answer is : %f,%f",x1,x2);
printf("\n");
}

这个是实数范围内的 二次方程解法.
复数范围内的只要是条件m<0 的地方改成 有i的 式子就可以了..

就像你这么写,把=换成==就行了