Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <conio.h>
- #include <stdlib.h>
- #include <locale>
- //Quadratic equation solver
- using namespace std;
- int D, a, b, c, x1, x2, d;
- double qq;
- int main(){
- start:
- cout << "Sqrt is a sqare root\n";
- cout << "Enter a\n";
- cin >> a;
- cout << "Enter b\n";
- cin >> b;
- cout << "Enter c\n";
- cin >> c;
- D = (pow(b, 2) - (4 * a * c));
- cout << "D = " << D << endl;
- if (D < 0){
- cout << "X1, X2 = varnothing\n";
- system("pause");
- return 0;
- }
- else if (D == 0){
- x1 = (b * -1) / (2 * a);
- x2 = x1;
- }
- else{
- qq = sqrt(D);
- if (D / qq == qq){
- x1 = ((b * -1) - qq) / (2 * a);
- x2 = ((b * -1) + qq) / (2 * a);
- }
- else{
- a = a * 2;
- cout << "X1 = -" << b << " - sqrt of" << D << "/ " << a << "\n";
- cout << "X2 = -" << b << " + sqrt of" << D << "/ " << a << "\n";
- system("pause");
- return 0;
- }
- }
- cout << "X1 = " << x1 << "\nX2 = " << x2 << "\n";
- system("pause");/*
- cout << "\nDo you want to do it again?" << "\nIf yes then enter 1, else enter 0" << endl;
- cin >> d;
- if (d == 1)*/
- goto start;
- //else
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement