Coding solution of quadratic equation

Can i get the code of this question please?

hi @eshaagarwal20cse_d81479fa0304b4e5
The input corresponds to equation ax^2 + bx + c = 0. Roots = (-b + sqrt(b^2 - 4ac))/2a , (-b - sqrt(b^2 - 4ac))/2a

Algo:

  1. Calculate the D viz, sqrt(b * b - 4 * a * c).
  2. If D < 0,
    2.1 print Imaginary
  3. if D == 0,
    3.1 print Real and Equal
    3.1 Calculate roots using formula ( - b + D) / (2 * a) and (- b - D)/ (2 * a)
    3.2 Print the roots
  4. If D > 0,
    4.1 print Real and Distinct
    4.2 Calculate roots using formula ( - b + D) / (2 * a) and (- b - D)/ (2 * a)
    4.3 print the roots (in non-decreasing order)
  5. End

refer this code -->

Please search the bug in this code.

#include #include<math.h> using namespace std; int main() { double a,b,c; cin>>a>>b>>c; double D= ((bb) - (4ac)); //Determinant double x1 = ((-b) + sqrt(D))/(2a); double x2 = ((-b) - sqrt(D))/(2*a); double first, second; if(x1>x2){ first=x2; second = x1;} else{ first=x1; second=x2; } if(D>0){ cout<<“Real and Distinct”<<endl; cout<<first<<" “<<second; } else if(D==0){ cout<<“Real and same”<<endl; cout<<”"<<first; cout<<" "<<second; } if(D<0){ cout<<“imaginary”; } return 0; }

hi @eshaagarwal20cse_d81479fa0304b4e5
save ur code on coding blocks ide and send link…

This code is running successfully but showing two test cases are wrong

hi @eshaagarwal20cse_d81479fa0304b4e5
there were 2 mistakes in ur code -->

  1. in line 23 u had written Real and same, while it should be Real and Equal
  2. in line 30 u had written imaginary, make i capital (Imaginary).

corrected code -->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.