// Program to find out roots of a quadratic equation. // Assignment-05 // quadeq.cpp, Author - Krishna Kumar Khatri. // Uncomment ONLY the following line if you are using Turbo/Borland compiler. // #define TC #ifdef TC #include #include #else #include #include using namespace std; #endif #include // For getch. short sign(const int& val) { return val < 0 ? -1 : (val > 0 ? 1 : val); } int main() { #ifdef TC clrscr(); #endif static int a, b, c; int deter = 0; float res; cout << "For equation, ax^2 + bx + c = 0" << endl << "enter a, b, and c's values: "; cin >> a >> b >> c; deter = b * b - 4 * a * c; cout << endl; switch (sign(deter)) { case -1: cout << "Roots are imaginary."; break; case 0: cout << "Roots are equal, and each is " << -b / (2 * a); break; case 1: cout << "First root is, " << (-b + sqrt((double)deter)) / (2 * a); cout << " and second one is, " << (-b - sqrt((double)deter)) / (2 * a); break; } cout << endl << endl << "Program over. Press any key to exit..."; getch(); return 0; // Successful termination. }