Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- double a,b,c,root1,root2,comp;
- cin>>a>>b>>c;
- double x;
- x = (b*b) - (4*a*c);
- if (x>0)
- {
- root1= ((-b)+sqrt(x))/(2*a);
- root2= ((-b)-sqrt(x))/(2*a);
- cout<<"Root 1 = "<<root1<<"\nRoot 2 = "<<root2;
- }
- else if(x==0)
- {
- root1=root2=(-b/(2*a));
- cout<<"Root 1 = "<<root1<<"\nRoot 2 = "<<root2;
- }
- else if(x<0)
- {
- root1=root2=(-b)/(2*a);
- comp=(sqrt(-x))/(2*a);
- cout<<"Root 1 = "<<root1<<"+ i "<<comp<<"\nRoot 2 = "<<root2<<"- i "<<comp;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement