Click here to Skip to main content
11,576,667 members (57,739 online)
Click here to Skip to main content

Tagged as

A simple program to solve quadratic equations with

, 15 Nov 2010 CPOL 2.1K 2
I am reposting this because I accidentally deleted my first post.The solution is presented as a pair of complex roots, unless a == 0, in which case the equation is linear and returns a single complex(real) root.If a == 0 and b == 0, the function fails.Given a complex type, replace...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

16 Nov 2010
Alain Rist
I prefer this :) #include #include #include #include static const double bad_double = std::numeric_limits::quiet_NaN();class QuadSolver{ static bool IsZero(double val) { return (val == 0) || (fabs(val) <...
8 Nov 2010
Anshul R
Simple and prints imaginary roots too!float a,b,c,x1,x2,d,dsq;printf("ax^2 + bx + c = 0");printf("\nEnter a,b,c separated by commas : \n");scanf("%f,%f,%f",&a,&b,&c);d = b*b-(4*a*c);if(d>=0){dsq=sqrt(d);x1 = (-b+dsq)/(2*a);x2 = (-b-(dsq))/(2*a);printf("\nRoot 1 : %f\nRoot 2...
9 Nov 2010
YvesDaoust
// Real solutions of the quadratic equation A x^2 + B x + C = 0// Returns two roots (possibly identical) in increasing order, or nonebool Quadratic(double A, double B, double C, double R[2]){ if (A == 0) { // Linear, impossible or degenerate, cannot find two roots ...
10 Nov 2010
federico.strati
The correct way to solve quadratic equations is none of the above. For the correct algorithm as applied in the following function, seenumerical recipes in C and the Wolfram site at http://mathworld.wolfram.com/QuadraticEquation.html#include bool quadratic(double a, double b,...
20 May 2010
ReymonARG
#include #include #include "Raiz_Cuadratica.h"int main(){ // float xx = 1; float x = 1; float i = -12; RaizCuadratica *lala = new RaizCuadratica( xx, x, i ); RaizCuadratica::sRaiz raiz = lala->GetRaiz(); printf( "x1 = %f || x2 = %f\n\n",...
11 Nov 2010
Software_Developer
7 alternatives  
A simple program to calculate quadratic equation with.Input MUST have the format:AX2 + BX + C = 0EXAMPLE: input the equation 2X2 + 4X -30 = 0 as:A= 2 B= 4 C= -30The answers for AX2 + BX + C = 0 should be 3 and -5.x1=3x2=-5 bool solver(float...
7 Nov 2010
TomSeaton
#include<stdio...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Michael Waters
Engineer
United States United States
BS Aerospace Engineering 1993, University of Virginia
ME Aerospace Engineering 1995, University of Virginia

| | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 15 Nov 2010
Article Copyright 2010 by Michael Waters
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid