#788: 最後的測試一直錯


kai120420 (老吳)


*** 第 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;
      }

不知道為什麼會錯= =

#809: Re:最後的測試一直錯


weiching1123 (我要上清大)


*** 第 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; 
      }

不知道為什麼會錯= =

在上面需要再加一個#include<math.h>

#848: Re:最後的測試一直錯


kai120420 (老吳)


謝謝囉 我成功了