#32149: 測試通過,解答NA,求解


leo940625@gmail.com (Devil 小天o)


#include <iostream>
#include <cmath>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//g++ test.cpp -o test
//.\test.exe

int main(int argc, char** argv) {
   
    int a,b,c,d;
    int a1,a2;
    cin>>a>>b>>c;
    d=b*b-4*a*c;
   
    if(d>0)    {
       
     a1=(-b+sqrt(d))/2*a;    
     a2=(-b-sqrt(d))/2*a;
     cout<<"Two different roots x1="<<a1<<" , x2="<<a2;
   
    }
    else if(d==0) {
   
     a1=(-b)/2*a;
     cout<<"Two same roots x="<<a1;
   
    }
    else{
       
     cout<<"No real root";
       
    }
   
    return 0;
   
}
#32150: Re: 測試通過,解答NA,求解


cges30901 (cges30901)


2*a要括號