#include "stdafx.h" #include <iostream> #include <cmath> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { double quadratic,linear,cons ; double num1,num2=0; double power; cout<<"Enter the coefficient of the quadratic term>"; cin>>quadratic; cout<<"Enter the coefficient of the linear term>"; cin>>linear; cout<<"Enter the constant term>"; cin>>cons; cout << "The solution to the equation" << quadratic << "x^2 +" << linear << "x + " << cons << "= 00.00000"; power=pow (linear / 2 , 2.0); num1= ( - linear + sqrt(power - ( 4 * quadratic * cons )) ) / (2 * quadratic); num2= ( - linear - sqrt(power - ( 4 * quadratic * cons )) ) / (2 * quadratic); cout<<"is {"<<num1<<","<<num2<<"}"; return 0; } |
|
|
Enter the coefficient of the quadratic term>4 Enter the coefficient of the linear term>5 Enter the constant term>6 The solution to the equation 4.00000x^2 + 5.00000x + 6.00000 = 0.00000 is {-1.#IND0,-1.#IND0} Press any key to exit. |