Advertisement
AntonioVillanueva

Ecuación de segundo grado - Equation du second degré

Nov 7th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double delta(double a,double b,double c){//Interieur racine
  6.     return ((pow(b,2)-(4 * a * c)) );  
  7. }
  8.  
  9. double racine(double a,double b,double c){
  10.     return sqrt (abs (delta(a,b,c)));  
  11. }
  12.  
  13.  
  14. int main() {
  15.     double a,b,c;
  16.  
  17.     cout<<" a= ";cin>>a;
  18.     cout<<" b= ";cin>>b;
  19.     cout<<" c= ";cin>>c;
  20.    
  21.     cout <<endl<<a<<"x^2+"<<b<<"x+"<<c<<"=0"<<endl<<endl;
  22.  
  23.     if (delta(a,b,c)>=0){//Sol.Reel
  24.         cout <<"x1=\t"<<((-b + racine(a,b,c))/(2*a*1.0))<<endl
  25.              <<"x2=\t"<<((-b - racine(a,b,c))/(2*a*1.0))<<endl;
  26.     }else{//Sol.Complexe
  27.         cout <<"x1=\t"<<((-b)/(2*a*1.0)) <<"+"<< racine(a,b,c)/(2*a*1.0)<<'i'<<endl;
  28.         cout <<"x2=\t"<<((-b)/(2*a*1.0)) <<"-"<< racine(a,b,c)/(2*a*1.0)<<'i'<<endl;                   
  29.     }
  30.    
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement