-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (36 loc) · 1.01 KB
/
main.cpp
File metadata and controls
41 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <cmath>
#include <complex>
using namespace std;
int main()
{
int a,b,c;
int nRoots;
int value;
bool isDone=false;
complex<float> firstRoot=4+1i;
complex<float> secondRoot=2i;
while(isDone==false){
cout << "\nenter the coefficient of the following variables:\nax^2+bx+c=0\na=";
cin >> a;
cout << "\nb=";
cin >> b;
cout << "\nc=";
cin >> c;
nRoots= ( pow(b,2) - (4 * a * c) );
if(nRoots==0){
cout << "the root of equation is : ";
cout<< ( -b + sqrt(pow(b,2) - ( 4 * a * c)) ) / (2 * a) << endl;
}
else if(nRoots>0){
cout << "the roots of the equation are:\n1) ";
cout<< ( -b + sqrt(pow(b,2) - ( 4 * a * c)) ) / (2 * a) << endl;
cout<< "2) " << ( -b - sqrt(pow(b,2) - ( 4 * a * c)) ) / (2 * a) << endl;
}
else if(nRoots<0)
{
cout << complex<double>(sqrt(pow(b,2) - ( 4 * a * c))) << endl << "2) " << endl;
}
}
return 0;
}