*** 第 5 點 (20%):WA
與正確輸出不相符(line:1)
您的答案為: Two same roots x=-4
正確答案為: Two same roots x=-1
#include <stdio.h>
int main()
{ int a,b,c;
double x1,x2;
while(scanf("%d%d%d",&a,&b,&c)>0)
{
x1=(-b+sqrt(b*b-4*a*c))/2*a;
x2=(-b-sqrt(b*b-4*a*c))/2*a;
if(x1>x2 && b*b-4*a*c>0)printf("Two different roots x1=%.0lf , x2=%.0lf\n",x1,x2);
if(x1<x2 && b*b-4*a*c>0)printf("Two different roots x1=%.0lf , x2=%.0lf\n",x2,x1);
if(x1==x2 && b*b-4*a*c==0)printf("Two same roots x=%.0lf\n",x1);
if(b*b-4*a*c<0)printf("No real root\n");
}
return 0;
}
不知道為什麼會錯= =
*** 第 5 點 (20%):WA
與正確輸出不相符(line:1)
您的答案為: Two same roots x=-4
正確答案為: Two same roots x=-1
#include <stdio.h>
int main()
{ int a,b,c;
double x1,x2;
while(scanf("%d%d%d",&a,&b,&c)>0)
{
x1=(-b+sqrt(b*b-4*a*c))/2*a;
x2=(-b-sqrt(b*b-4*a*c))/2*a;
if(x1>x2 && b*b-4*a*c>0)printf("Two different roots x1=%.0lf , x2=%.0lf\n",x1,x2);
if(x1<x2 && b*b-4*a*c>0)printf("Two different roots x1=%.0lf , x2=%.0lf\n",x2,x1);
if(x1==x2 && b*b-4*a*c==0)printf("Two same roots x=%.0lf\n",x1);
if(b*b-4*a*c<0)printf("No real root\n");
}
return 0;
}
不知道為什麼會錯= =