#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c;
double x1,x2,m,n,t;
scanf("%d%d%d",&a,&b,&c);
if (a==0)
{if (b==0) printf("Input error!\n");
else if (b!=0)
printf("x=%.6lf\n",-c/b);}
if (a!=0) t=b*b-4*a*c;
{if (t=0)
printf("x1=x2=%.6lf\n",-b/(2*a));
if (t>0)
x1=(-b+sqrt(t))/(2*a)
x2=(-b-sqrt(t))/(2*a)
printf("x1=%.6lf\n",x1);
printf("x2=%.6lf\n",x2);
if (t<0)
m=-b/(2*a);n=sqrt(t)/(2*a);
printf("x1=%.6lf+%.6lfi\n",m,n);
printf("x1=%.6lf-%.6lfi\n",m,n);}
}
这个程序哪里出现的错误,为什么总是通不过呢?
我稍微改了下。。。你试一下吧。。。
#include<stdio.h>
#include<math.h>
void main(){
float a,b,c,m,n;
float x,x1,x2,t;
printf("please input the number:\n");
scanf("%f%f%f",&a,&b,&c);
if (a==0){
if (b==0) printf("Input error!\n");
if (b!=0)
printf("x=%.6lf\n",-c/b);
}
if (a!=0) {
t=b*b-4*a*c;
//printf("t=%f\n",t);
if (t==0){
printf("x1=x2=%.6lf\n",-b/(2*a));
}
if (t>0){
x1=(-b+sqrt(t))/(2*a);
x2=(-b-sqrt(t))/(2*a);
printf("x1=%.6lf\n",x1);
printf("x2=%.6lf\n",x2);
}
if (t<0){
m=-b/(2*a);n=sqrt(-t)/(2*a);
printf("x1=%.6lf+%.6lfi\n",m,n);
printf("x1=%.6lf-%.6lfi\n",m,n);
}
}