Advertisement
Mlack

911. Квадратное уравнение

Dec 29th, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. //911. Квадратное уравнение
  2. //zadacha from e-olimp
  3.  
  4. #include<iostream>
  5. #include<cmath>
  6. #include<cstdlib>
  7. #include<cstdio>
  8. using namespace std;
  9. int main()
  10. {
  11.    int a,b,c,x1,x2;
  12.    double d;
  13.    cin>>a>>b>>c;
  14.    d=b*b - 4 * a * c;
  15.    x1=(-b + sqrt(d)) / 2 * a;
  16.    x2=(-b - sqrt(d)) / 2 * a;
  17.    if (d < 0) {cout<<"No roots"<<endl; exit(0);}
  18.    if (d == 0) {cout<<"One root:"<<" "<<x1<<endl; exit(0);}
  19.    if (d > 0) {
  20.       if (x1 < x2) {cout<<"Two roots:"<<" "<<x1<<" "<<x2<<endl; exit(0);}
  21.       if (x1 >= x2) {cout<<"Two roots:"<<" "<<x2<<" "<<x1<<endl; exit(0);}
  22.               }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement