Advertisement
2002ASP Math #7837

Calculates Quadratic Formula

This code applies the quadratic formula to an equation and derives the variable value given the three coefficients.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
#include <iostream.h>
#include <math.h>
void main()
{
 double A;
 double B;
 double C;
 double disc;
 cout << "Enter A: ";
 cin >> A;
 cout << "Enter B: ";
 cin >> B;
 cout << "Enter C: ";
 cin >> C;
 disc = B*B - 4*A*C;
 if (disc < 0){
 cout << "Imaginary results: " << endl;
 cout << "(" << B * (-1) << " + " << sqrt(disc * (-1)) << "i) / " << 2*A << endl;
 cout << "(" << B * (-1) << " - " << sqrt(disc * (-1)) << "i) / " << 2*A << endl;
 }
 else if (disc == 0){
 cout << "Single result: " << (-B)/(2*A) << endl;
 }
 else{
  cout << "Two results: " << endl;
  cout << (B * (-1) + sqrt(disc)) / (2*A) << endl;
  cout << (B * (-1) - sqrt(disc)) / (2*A) << endl;
 }
}
Original Comments (3)
Recovered from Wayback Machine