Quadratic Equation in C++

A quadratic equation has the form ax4 + bx3 + cx2 + dx + e = 0. A general quartic equation (also called a biquadratic equation) is a fourth-order polynomial equation of the form.

Source Code

#include <iostream>
#include <cmath>
#include <windows.h>
using namespace std;
int main() {

    float a = 0.0 ;
    float b = 0.0 ;
    float c = 0.0 ;
    float x1 = 0.0 ;
    float x2 = 0.0 ;
    float dtrmnt = 0.0 ;
    float real = 0.0 ;
    float imgpart = 0.0 ;
    system("color 4a");
    cout<<"\n\n\t********** Quadratic Equation *************\n\n\n";
    cout << "Enter Coefficients A : ";
    cin >> a ;
    cout << "\n Enter Coefficients B : ";
    cin >> b ;
    cout << "\n Enter Coefficients C : ";
    cin >> c ;
    dtrmnt = b*b - 4*a*c;
              if (dtrmnt > 0) {
        x1 = (-b + sqrt(dtrmnt)) / (2*a);
        x2 = (-b - sqrt(dtrmnt)) / (2*a);
        cout<<endl<<endl;
                        cout << "x1 = " << x1 << endl;
        cout << "x2 = " << x2 << endl;
    }
   else if (dtrmnt == 0) {
        x1 = (-b + sqrt(dtrmnt)) / (2*a);
        cout<<endl<<endl;
                        cout << "x1 = x2 =" << x1 << endl;
    }
 else {
        real = -b/(2*a);
        imgpart =sqrt(-dtrmnt)/(2*a);
        cout<<endl<<endl;
        cout << "x1 = " << real << "+" << imgpart << "i" << endl;
        cout << "x2 = " << real << "-" << imgpart << "i" << endl;
    }
return 0;
}

Output of the Program

Quadratic Equation in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment