Write a program to obtain answer by entering a Quadratic function from the ser.(using visual studio)
![1. Write a program to obtain answer by entering a Quadratic function from the
user.(using visual studio)
output screen
Enter the coefficient for the Quadratic term : 00
Enter the coefficient for the linear term : 00
Enter the coefficient for the Constant term : 00
entered Quadratic function
y
= 00x^2 + 00x + 00
answer is
00, 00](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc9284d0a-d8a8-4692-8b62-fd92db1fe004%2Fd0954402-12c9-48b2-bebc-847efa6cb221%2Fskm0rse_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
CODE:
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a,b,c;
cout<<"Enter the coefficient for the quadratic term : ";
cin>>a;
cout<<"Enter the coefficient for the linear term : ";
cin>>b;
cout<<"Enter the coefficient for the constant term : ";
cin>>c;
cout<<"Entered Quadratic Function : y = "<<a<<"x^2 + "<<b<<"x + "<<c;
cout<<"\nAnswer is\n";
double x1, x2, discriminant, realPart, imaginaryPart;
discriminant = b*b - 4*a*c;
if(a==0 && b==0 && c==0)
cout<<"00, 00\n";
else if(a==0)
cout<<((-1*c)/b)<<"\n";
else if (discriminant > 0) {
x1 = (-b + sqrt(discriminant)) / (2*a);
x2 = (-b - sqrt(discriminant)) / (2*a);
cout<<x1<<" , "<<x2<<"\n";
}
else if (discriminant == 0) {
x1 = -b/(2*a);
cout << x1<<" , "<< x1 <<"\n";
}
else {
realPart = -b/(2*a);
imaginaryPart =sqrt(-discriminant)/(2*a);
cout << realPart << "+" << imaginaryPart << "i" << " , ";
cout << realPart << "-" << imaginaryPart << "i" <<"\n";
}
}
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)