SHARE
TWEET

Untitled

a guest Feb 14th, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main()
  5. {
  6.     double a,b,c,root1,root2,comp;
  7.     cin>>a>>b>>c;
  8.     double x;
  9.     x = (b*b) - (4*a*c);
  10.     if (x>0)
  11.     {
  12.     root1= ((-b)+sqrt(x))/(2*a);
  13.     root2= ((-b)-sqrt(x))/(2*a);
  14.     cout<<"Root 1 = "<<root1<<"\nRoot 2 = "<<root2;
  15.  
  16.     }
  17.     else if(x==0)
  18.     {
  19.         root1=root2=(-b/(2*a));
  20.         cout<<"Root 1 = "<<root1<<"\nRoot 2 = "<<root2;
  21.     }
  22.     else if(x<0)
  23.     {
  24.         root1=root2=(-b)/(2*a);
  25.         comp=(sqrt(-x))/(2*a);
  26.         cout<<"Root 1 = "<<root1<<"+ i "<<comp<<"\nRoot 2 = "<<root2<<"- i "<<comp;
  27.  
  28.     }
  29.     return 0;
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top