/* * The Spar Library - modular math parser * Copyright (C) 2000,2001 Davide Angelocola * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */ #define SL_MODULE_BUILTIN #include #include #include #define MODULE_NAME "solve_q" #define MODULE_DESC "Solve quadratic equations" #define MODULE_VER "0.1" int solve_q_main (void) { double a, b, c; double x1, x2; int nroots; sl_writeln ("Real roots of (a*x^2) + (b*x) + c = 0"); sl_writeln (""); sl_input_double ("input 'a'", &a); sl_input_double ("input 'b'", &b); sl_input_double ("input 'c'", &c); nroots = sl_poly_solve_quadratic (a, b, c, &x1, &x2); sl_writeln (""); switch (nroots) { case 0: sl_writeln ("no real roots."); break; case 1: sl_writeln ("one real root:"); sl_write_value_with_label ("x1", x1); break; case 2: sl_writeln ("two reals roots:"); sl_write_value_with_label ("x1", x1); sl_write_value_with_label ("x1", x2); break; } return SL_SUCCESS; } sl_module solve_quadratic = { MODULE_NAME, MODULE_DESC, MODULE_VER, solve_q_main }; SL_MODULE_EXPORT(solve_quadratic);