#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,x;
double disc,x1,x2;
scanf("%d %d %d",&a,&b,&c);
disc=b*b-4*a*c;
if (fabs(disc)<1e-6)
printf("\"NO\"");
else
{
if (fabs(disc)>1e-6)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
if (x1==(int)x1&&x2==(int)x2)
printf("%d %d",x1,x2);
else printf("\"NO\"");
}
else
{
x=(-b)/2*a;
if (x=(int)x)
printf("%d",x);
else printf("NO");
}
}
return 0;
}
1 回答
已采纳
qq_莫非
TA贡献257条经验 获得超92个赞
#include <stdio.h> #include <math.h> void main () { double sqrt(double x); int a,b,c; double x1,x2,x,e,d,g,f; scanf("%d %d %d",&a,&b,&c); d=b*b-4*a*c; if (a==0) { if (b!=0) {x=-(double)c/(double)b; if (x==0) {x=-x; printf("x=%.6lf\n",x);} else printf("x=%.6lf\n",x); } else printf("Input error!\n");} else if (d<0) {d=-d; e=sqrt(d); g=-(double)b/(2*(double)a); f=e/(2*a); if (g!=0) printf("x1=%.6lf+%.6lfi\nx2=%.6lf-%.6lfi\n",g,f,g,f); else printf("x1=%.6lfi\nx2=-%.6lfi\n",f,f);} else if (d==0) { x1=x2=-b/(2*a); printf("x1=x2=%.6lf\n",x1);} else { e=sqrt(d); x1=(-b+e)/(2*a); x2=(-b-e)/(2*a); printf("x1=%.6lf\nx2=%.6lf\n",x1,x2);} }
- 1 回答
- 0 关注
- 1212 浏览
添加回答
举报
0/150
提交
取消