Question

can any one please help me with this c++ code ASAP

media%2F018%2F018c81ca-ffdf-4aef-8120-62

media%2F9cf%2F9cf6cd4a-97d0-4cdc-ab27-a2

can any one please help me with this c++ code ASAP

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<cmath>
using namespace std;
int main() {
double a,b,c,disc,root1,root2,real,imag;
cout<<"This program calculates the root of a\n";
cout<<"      quadratic equation of the form\n";
cout<<"       ax + bx + c = 0\n\n";
cout<<"Please enter values of a,b and c: ";
cin>>a>>b>>c;
if(a==0 && b==0)
cout<<"The equation is degenerate and had no roots.\n";
else if(a==0)
cout<<"The equation has single root x = "<<-c/b<<endl;
else
{
disc=pow(b,2.0) -4*a*c;
if(disc>0.0)
{
disc=sqrt(disc);
root1=(-b + disc)/(2*a);
root2=(-b - disc)/(2*a);
cout<<"The two real roots are"<<root1<<"and"<<root2<<endl;
}
else if(disc<0.0) {
real = -b/(2*a);
imag =sqrt(-disc)/(2*a);
cout << "Both roots are imaginary.The 2 roots are " << endl;
cout << real << "+" << imag << "i" << endl;
cout <<real << "-" << imag << "i" << endl;
}
else
cout<<"Both roots are equal to "<<-b /(2*a)<<endl;
}
return 0;
}

Result... compiled and executed in 6.982 sec(s) This program calculates the root of a quadratic equation of the form ax +bxC-0 Please enter values of a,b and c: 2 3 4 Both roots are imaginary.The 2 roots are -0.75+1.19896i -0.75-1.19896i

Add a comment
Know the answer?
Add Answer to:
can any one please help me with this c++ code ASAP
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT