Programming
Python
R
Java
C
C++
C#
WEB
HTML
CSS
JavaScript
BootStrap4
jQuery
SVG
MORE
Examples1
Python
GO
R
Java
C
C++
C#
Examples2
Python
R
Java
C
C++
C#
HTML
CSS
JavaScript
BootStrap4
jQuery
SVG
Seo Tools
Code Minifier
Code Beautifier
Language Compiler
Misc Tools
File Converter
References
C
C++
Python
Java
PHP
JavaScript
Examples
Python
R
Java
C
C++
C#
HTML
CSS
JavaScript
BootStrap4
jQuery
SVG
Home
About
Contact
JetPack
Multi Themes-->>
Code it ALL
Scroll TOP
C++ Program to Find All Roots of a Quadratic Equation - CodeGK
Δ Cpp Examples
Examples
C++ "Hello, World!" Program
C++ Program to Add Two Numbers
C++ Program to Find Quotient and Remainder
C++ Program to Find Size of char, bool, int, float, double and long
C++ Program to Swap Two Numbers
C++ Program to Check Whether Number is Even or Odd
C++ Program to Check Whether an Alphabet is a Vowel or Consonant
C++ Program to Find Largest Number Among Three Numbers
C++ Program to Find Smallest Number Among Three Numbers
C++ Program to Find All Roots of a Quadratic Equation
C++ Program to Calculate Sum of Natural Numbers
C++ Program to Check Leap Year
C++ Program to Find Factorial
C++ Program to Generate Multiplication Table
C++ Program to Display Fibonacci Series
C++ Program to Find GCD
C++ Program to Find LCM
C++ Program to Reverse a Number
C++ Program to Calculate Power of a Number
C++ Program to Find ASCII Value of a Character
C++ Program to Multiply two Numbers
C++ Program to Check Whether a Number is Palindrome or Not
C++ Program to Check Whether a Number is Prime or Not
C++ Program to Display Factors of a Number
♦ C++ Program to Find All Roots of a Quadratic Equation
♣ Example1: C++ Program to Find All Roots of a Quadratic Equation
Input:
Run CODE
Reload Code
Copy Code
#include
#include
using namespace std; void solveQuadratic(float a, float b, float c){ if((b*b-4*a*c)>=0){ float root1; root1= (-1*b + sqrt(b*b-4*a*c))/(2*a); float root2; root2= (-1*b - sqrt(b*b-4*a*c))/(2*a); printf("This equation has root as %f and %f\n", root1, root2); } else{ printf("No real root(s) exist for this equation\n"); } } int main() { // Equation x^2-7x+12; float a1=1; float b1=-7; float c1=12; solveQuadratic(a1, b1, c1); // Equation x^1+2x+2; float a2=1; float b2=2; float c2=2; solveQuadratic(a2, b2, c2); return 0; }
Output: