Raices
Categorías: Lenguaje C++ |
1 // raices
2
3 #include <iostream>
4 #include <math.h>
5 using namespace std;
6
7 int main (){
8 float a=0.0, b=0.0, c=0.0, x1=0.0, x2=0.0, aux=0.0;
9 cout <<"Ingrese los coeficientes del polinomio\n";
10 cout <<"a ";
11 cin >>a;
12 cout <<"b ";
13 cin >>b;
14 cout <<"c ";
15 cin >>c;
16 aux=b*b-4*a*c;
17 if(aux>0){
18 x1=(-b+sqrt(aux))/(2*a);
19 x2=(-b-sqrt(aux))/(2*a);
20 cout <<"Las raices del polinomio son: "<<x1 <<" y " <<x2 <<"\n";
21 }
22 else if(aux==0)
23 cout <<"la raiz del polinomio es "<< -b/(2*a)<<"\n";
24 else{
25 x1=sqrt(-aux)/(2*a);
26 x2=-b/(2*a);
27 cout <<"las raices del polinomio son "<<x2<<"+"<<x1<<"i y" <<x2 <<"-" <<x1 <<"i\n";
28 }
29 return 0;
30 }
