#30149: c++解答


mephistoxfaust@gmail.com (舟梅浮永不逆)


#include<iostream>
#include <math.h>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c ;
    int d, e,f ;
    
    d = ((-b + (sqrt((b*b)-(4*a*c))))/2*a);
    e = ((-b - (sqrt((b*b)-(4*a*c))))/2*a);
    f = -b/(2a)
    
    if (((b*b )- (4*a*c)) > 0 )
        
        
        cout << "Two different roots "<< "x1="<< d <<" "<< ", " << "x2=" << e ;
    
    else if (((b*b )-(4*a*c)) == 0 )
        
        cout << "Two same roots " << "x="<< f ;
    
    else  
        cout << "No real root" ;
    
    
     
    
    return 0;
}

 

#30150: Re: c++解答


mephistoxfaust@gmail.com (舟梅浮永不逆)


#include<iostream>
#include <math.h>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c ;
    int d, e,f ;
    
    d = ((-b + (sqrt((b*b)-(4*a*c))))/2*a);
    e = ((-b - (sqrt((b*b)-(4*a*c))))/2*a);
    f = -b/(2a);
    
    if (((b*b )- (4*a*c)) > 0 )
        
        
        cout << "Two different roots "<< "x1="<< d <<" "<< ", " << "x2=" << e ;
    
    else if (((b*b )-(4*a*c)) == 0 )
        
        cout << "Two same roots " << "x="<< f ;
    
    else  
        cout << "No real root" ;
    
    
     
    
    return 0;
}