0

an eqn of the form ax²+bx+c=0 known as quadratic equation . the values of x that satisfy the eqn are known as roots of the eqn

22nd Sep 2016, 2:09 AM
Meena
Meena - avatar
2 Antworten
+ 1
#include <iostream> #include <cmath> using namespace std; int main() { double a ,b ,c; double x1, x2; double det; cout<<"please enter a, b and c"<<endl; cin>>a>>b>>c; det=b*b-4*a*c; if(det>0) { x1=(-b+sqrt(det))/(2*a); x2=(-b-sqrt(det))/(2*a); cout<<"x1 = "<<x1<<endl; cout<<"x2 = "<<x2<<endl; } else if(det==0) { x1=(-b+sqrt(det))/(2*a); cout<<"x1 = x2 = "<<x1; } return 0; }
26th Sep 2016, 10:13 PM
Andres Mar
0
In the header, include <cmath>, then you can use sqrt() function to get quareroot of a number. Like so: sqrt(4) returns 2. I won't do comments on this as posting here is a right pain, if there are any questions on this, mail me andresmarivent@yahoo.com cheers
26th Sep 2016, 10:18 PM
Andres Mar