思路都要别人想可是很不利于学习哦!我给你一个例子吧
比方说求a*x*x+b*x+c=0(a不为0)
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#define EPS 1e-6
main()
{
float a, b, c,, disc, p, q;
priintf("please enter a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
if(fabs(a) <=EPS)
{
printf("it is not a correct equation!\n");
exit(0);
}
disc = b*b-4*a*c;
if(fabs(disc) <= EPS)
{
printf("two equal real roots: x1=x2=%6.2f\n",-b/(2*a));
}
else
{
p=-b/(2*a);
q=sqrt(fabs(disc))/(2*a);
if(disc>1e-6)
{
printf("two unequal real roots:x1=%6.2f,x2=%6.2f\n",p+q,p-q);
}
else
{
printf("two complex roots:\n");
printf("x1=%6.2f + %6.2f\n",p,q);
printf("x1=%6.2f - %6.2f\n",p,q);
}
}
}