Problem E1 The solution of the equation ax2 + bx + c has 6 cases, that can occur
ID: 3668841 • Letter: P
Question
Problem E1
The solution of the equation ax2 + bx + c has 6 cases, that can occur with various values of a, b, and c.
Test for these 6 cases in the order given here.
Do not compute any values until you have determined what calculations are needed.
The 6 cases are:
When a, b, and c are all zero, any value of x is a solution. Print: Any value of x is a solution.
When a and b are zero and c is not, no solution exists. Print: No solution exists.
When a is zero and b is not zero, the only solution is x = -c/b. Calculate the value of x and print the solution.
The remaining three cases are determined by the value of the determinant.
The determinant is b2 - 4ac.
Compute and save the value of the dererminant now.
You can use the value of the determinant you saved to select one of the remaining three cases.
When the determinant is zero, the only solution is x = -b/2a. Calculate the value of x and print the solution.
When the determinant is positive, two solutions are given by the following two expressions:
x1 = ( -b +
When the determinant is negative, the solutions have an imaginary component. Print: The solutions have an imaginary component.
If you are fimiliar with imaginary numbers, you may compute and print the result, but this is not required.
Test it 7 times:
a = 0 b = 0 c = 0
a = 0 b = 0 c = 4
a = 0 b = 8 c = -12
a = 2 b = 4 c = 2
a = 2 b = 2 c = 0
a = 100 b=100 c= -11
a = 1 b = 1 c = 1
Check your results by hand, by substituting your results back into the equation and verify that they are roots.
(C++, I USE CODEBLOCKS)
Explanation / Answer
#include <iostream>
#include <cmath>
using namespace std;
main()
{
int a,b,c;
float x;
cout<<"Please enter the value of a, b and c (Eg: 12 9 53): ";
cin>>a>>b>>c;
if(a == 0 && b == 0 && c == 0)
{
cout<<" Any value of x is the solution.";
return 0;
}
else if(a == 0 && b == 0 && c != 0)
{
cout<<" No solution exists.";
return 0;
}
else if(a == 0 && b != 0)
{
x = (float) -(c)/b;
cout<<" Only one solution is possible. x = "<<x;
return 0;
}
int determinant = b*b - 4*a*c;
if(determinant == 0)
{
x = (float) -(b)/(2*a);
cout<<" Only one solution is possible. x = "<<x;
}
else if(determinant > 0)
{
float x1 = -b + (float) sqrt(determinant);
float x2 = -b - (float) sqrt(determinant);
cout<<" Two solution are possible. x1 = "<<x1<<" x2 = "<<x2;
}
else if(determinant < 0)
cout<<" The solutions have an imaginary component.";
return 0;
}
//Hope it helps. :-)
//Please comment if you're facing any issue. I'll try modify as per your requirement.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.