Program to implements the quadratic formula


    # include <iostream.h>
    # include <math.h>          //defines the sqrt( ) function
         int main( )
         {                     
        //implements the quadratic formula
        double a, b, c ;
        cout <<"Enter the coefficients : "<<endl;
        cout << "\t a : ";
        cin >>a;
        cout << "\t b : ";
        cin >>b ;
        cout << "\t c : ";
        cin >> c ;

        cout<<"  The equation is : " << a << " * x * x + " << b << " * x + " << c << " = 0 " <<endl;

        double d = b * b - 4 * a * c ;
        double sqrtd = sqrt (d);
        double x1 = ( - b + sqrtd) / (2 * a ) ;
        double x2 = ( - b - sqrtd) / (2 * a ) ;
   
        cout << "The Solution are  : " <<endl;
        cout << "\t x1 =" <<x1 <<endl;
        cout << "\t x2 =" <<x2 <<endl;
        cout <<"Check : " <<endl;
        cout <<"\t a*x1*x1 + b*x1 + c = " << a*x1*x1 + b*x1 + c<<endl;
        cout <<"\t a*x2*x2 + b*x2 + c = " << a*x2*x2 + b*x2 + c<<endl;

        return 0;
    }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|