Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- double a, b, c, D, y1, y2, x1, x2, x3, x4; //We are solving bi-square equation of the kind ax^4+bx=0 , where a,b and c are coefficients
- //D is the discriminant.We replace x^2=y so we get an equation where y1 and y2 are radicals of the square equation
- //x1,x2,x3,x4 are radicals of the bi-square equation
- bool IsStarted = true;
- do
- {
- cout << "a="; cin >> a;
- cout << "b="; cin >> b;
- cout << "c="; cin >> c;
- //the acer input values of the coefficients
- //if a=0 then we have incomplete quadratic equation
- if (a == 0 ||b==0||c==04)
- {
- cout << "please,input value different from 0" << endl;
- continue;
- }
- D = (b * b - 4 * a * c);
- cout << "D=" << D << endl;
- //depending on the discriminant we consider 3 cases
- if (D < 0)
- {
- cout << "the equation has no solution" << endl;
- //one of the cases is when the discriminant is lower than zero,then the equation doesnt have solution
- }
- if (D == 0)
- {
- y1 = y2 = -b / (2 * a);
- cout << "y1=y2=" << y1 << endl;
- //in case when the discriminant is equal to zero we have only one dual radical
- }
- if (D > 0)
- {
- y1 = -b / (2 * a) + sqrt(D) / (2 * a);
- y2 = -b / (2 * a) - sqrt(D) / (2 * a);
- cout << "y1=" << y1 << endl;
- cout << "y2=" << y2 << endl;
- //in case when the discriminant is bigger than zero,the square eguation has two radicals
- if (y1 >= 0)
- {
- x1 = -sqrt(y1);
- x2 = sqrt(y1);
- cout << "x=" << x1 << endl;
- cout << "x=" << x2 << endl;
- //if the first radical if bigger ot equal to zero we can find the two radicals of the bi-square equation
- }
- else if (y1 < 0)
- {
- cout << " " << endl;
- //if the first radical ot the square equation is lower than zero then we dont have x1 and x2
- }
- if (y2 >= 0)
- {
- x3 = -sqrt(y2);
- x4 = sqrt(y2);
- cout << "x=" << x3 << endl;
- cout << "x=" << x4 << endl;
- //if the seond radical of the square equation is bigger or equal to zero then we can find the other two radicals of the bi-square equation
- }
- else if (y2 < 0)
- {
- cout << " " << endl;
- //if the second radical of the square equation is lower than zero then we dont have x3 and x4
- }
- }
- IsStarted = false;
- } while (IsStarted);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement