728x90 AdSpace

Latest Article



Program Solve quadratic formula C++ Code





The following program solves the quadratic formula
(-b +/- sqrt(b^2 - 4ac)) / 2a
It inputs three real numbers for the formula variables a, b, and c. It computes the two solutions for the formula, and outputs the solutions. Please fill in the missing lines to complete the program?
------------------------------------------------------------

#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a, b, c; // Formula input variables.
double pos_solution; // Variable for the positive solution.
double neg_solution; // Variable for the negative solution.
//
// Prompt for and input the three variables.
//
cout << "Input three real numbers, separated by spaces: ";
cin >> a >> b >> c;
//
// Compute the solutions to the formula.
//
pos_solution = (-b + sqrt(pow(b, 2.0) - 4.0 * a * c)) / (2.0 * a);
neg_solution = (-b - sqrt(pow(b, 2.0) - 4.0 * a * c)) / (2.0 * a);
//
// Output the results
//
cout << "The positive and negative solutions are: "
<< pos_solution << ", "
<< neg_solution
<< endl;
return 0;
}
------------------------------------------------------------------------------------------------------------


no image
  • Title : Program Solve quadratic formula C++ Code
  • Posted by :
  • Date : 11:37
  • Labels :






  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment