#5036: __不懂


heosphoros (冥)


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
 double a,b,c,d,x1,x2,x;
 while(cin>>a>>b>>c)
 {
 d=b*b-4*a*c;
 if(d>0)
 {
  x1=(-b+sqrt(d))/(2*a);
  x2=(-b-sqrt(d))/(2*a);
  cout<<"Two different roots "<<"x1="<<x1<<'\0'<<",x2="<<x2<<endl;
 }
 else if(d==0)
  {
  x=-b/(2*a);
  if(x==-0)
  x=0;
  cout<<"Two same roots x="<<x<<endl;
 }
 else
 cout<<"No real root"<<endl;
   }
   return 0;
}
得到

*** 第 1 點 (20%):WA (line:1)
您的答案為: Two different roots x1=3

請問是錯哪裡呢

#5043: Re:不懂


yuchiao0921 (我的字典沒有放棄)


#include
#include
using namespace std;
int main()
{
 double a,b,c,d,x1,x2,x;
 while(cin>>a>>b>>c)
 {
 d=b*b-4*a*c;
 if(d>0)
 {
  x1=(-b+sqrt(d))/(2*a);
  x2=(-b-sqrt(d))/(2*a);
  cout<<"Two different roots "<<"x1="< }
 else if(d==0)
  {
  x=-b/(2*a);
  if(x==-0)
  x=0;
  cout<<"Two same roots x="< }
 else
 cout<<"No real root"<   }
   return 0;
}
得到

*** 第 1 點 (20%):WA (line:1)
您的答案為: Two different roots x1=3

請問是錯哪裡呢


應該是格式吧
#5054: Re:不懂


shangyang1112 (嘖)


#include <stdio.h>
#include <math.h>
int main(){
    int a,b,c,x1,x2;
    double d=0;//把double a,b,c...改成這樣之後就可以跑了 
    while(scanf("%d %d %d",&a,&b,&c)!=EOF){
        d=(b*b)-(4*a*c);
        if(d>0){
            x1=(-b+sqrt(d))/(2*a);
            x2=(-b-sqrt(d))/(2*a);
            printf("Two different roots x1=%d , x2=%d\n",x1,x2);
            }                 
        else if(d==0){
            x1=(-b)/(2*a);
            printf("Two same roots x=%d\n",x1);
            }
        else if(d<0){
            printf("No real root\n");
            }
    }
    return 0;
}
這是我的程式碼。

#5170: Re:不懂


heosphoros (冥)


#include
#include
int main(){
    int a,b,c,x1,x2;
    double d=0;//把double a,b,c...改成這樣之後就可以跑了 
    while(scanf("%d %d %d",&a,&b,&c)!=EOF){
        d=(b*b)-(4*a*c);
        if(d>0){
            x1=(-b+sqrt(d))/(2*a);
            x2=(-b-sqrt(d))/(2*a);
            printf("Two different roots x1=%d , x2=%d\n",x1,x2);
            }                 
        else if(d==0){
            x1=(-b)/(2*a);
            printf("Two same roots x=%d\n",x1);
            }
        else if(d<0){
            printf("No real root\n");
            }
    }
    return 0;
}
這是我的程式碼。

 

 

謝謝