By: Cenelia Gonzales
Description: This program can be use to solve Quadratic Equation or second-order polynomial equation with one variable "X".
Below is the screenshot of the program. The quadratic equation is in the form of A(X^2)+BX+C=0. I entered below the equation, X^2+4X-12=0, with their coefficients, A=1, B=4, and C=-12. Then, it displayed the two roots of the equation which is 2 and -6.
//Below are the Codes of the Progam:
#include <iostream.h>
#include <math.h>
#define sqr(x) (x)*(x)
#define clrscr() system("cls");
int main()
{
cout << "\t\t\tQUADRATIC EQUATION FORM:\n\n";
cout << "\t\t\t A(X^2)+BX+C=0\n\n";
cout << "ENTER COEFFICIENTS:\n";
float A, B, C, Delta;
cout << " A = ";
cin >> A;
cout << " B = ";
cin >> B;
cout << " C = ";
cin >> C;
cout << endl;
if(A == 0 && B != 0)
{
cout << "THIS EQUATION IS A FIRST DEGREE EQUATION\n";
cout << "THE SOLUTION IS: " << -C/B << endl;
}
else if(A == 0 && B == 0)
{
cout << "THIS EQUATION HAS NO SOLUTION";
}
else
{
Delta = sqr(B) - 4*A*C;
if(Delta < 0)
{
cout << "THIS EQUATION DONT HAVE ANY REAL ROOTS";
}
else if(Delta == 0)
{
cout << "THIS EQUATION HAVE A SINGLE ROOT: " << -B/(2*A) << endl;
}
else
{
cout << "THIS EQUATION HAVE TWO REAL ROOTS" << endl;
float X1 = (-B + sqrt(Delta)) / (2 * A);
float X2 = (-B - sqrt(Delta)) / (2 * A);
cout << " X1 = " << X1 << endl;
cout << " X2 = " << X2 << endl;
}
}
cout << "\nTHANKS FOR USING THIS PROGRAM!" << endl;
cin.get();
cin.get();
return 0;
}
#include <math.h>
#define sqr(x) (x)*(x)
#define clrscr() system("cls");
int main()
{
cout << "\t\t\tQUADRATIC EQUATION FORM:\n\n";
cout << "\t\t\t A(X^2)+BX+C=0\n\n";
cout << "ENTER COEFFICIENTS:\n";
float A, B, C, Delta;
cout << " A = ";
cin >> A;
cout << " B = ";
cin >> B;
cout << " C = ";
cin >> C;
cout << endl;
if(A == 0 && B != 0)
{
cout << "THIS EQUATION IS A FIRST DEGREE EQUATION\n";
cout << "THE SOLUTION IS: " << -C/B << endl;
}
else if(A == 0 && B == 0)
{
cout << "THIS EQUATION HAS NO SOLUTION";
}
else
{
Delta = sqr(B) - 4*A*C;
if(Delta < 0)
{
cout << "THIS EQUATION DONT HAVE ANY REAL ROOTS";
}
else if(Delta == 0)
{
cout << "THIS EQUATION HAVE A SINGLE ROOT: " << -B/(2*A) << endl;
}
else
{
cout << "THIS EQUATION HAVE TWO REAL ROOTS" << endl;
float X1 = (-B + sqrt(Delta)) / (2 * A);
float X2 = (-B - sqrt(Delta)) / (2 * A);
cout << " X1 = " << X1 << endl;
cout << " X2 = " << X2 << endl;
}
}
cout << "\nTHANKS FOR USING THIS PROGRAM!" << endl;
cin.get();
cin.get();
return 0;
}