Advertisement
idsystems

Practica 15 - Raices

Jan 16th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. // Program: raices.cc
  2. // Author:  Yoan Pinzon
  3. // Date:    Agosto 30, 2006
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.    float a, b, c, d, x1, x2;
  12.  
  13.    cout << "Calculo de Raices para Ax^2 + Bx + C = 0" << endl;
  14.    cout << "========================================" << endl;
  15.  
  16.    cout << "Entre el valor de A = "; cin >> a;
  17.    cout << "Entre el valor de B = "; cin >> b;
  18.    cout << "Entre el valor de C = "; cin >> c;
  19.  
  20.    d = ( b * b ) - ( 4 * a * c ); // discriminante
  21.  
  22.    x1 = -b + sqrt( d ); x1 /= 2 * a;
  23.    x2 = -b - sqrt( d ); x2 /= 2 * a;
  24.  
  25.    cout << endl;
  26.  
  27.    cout << "Las raices de \""
  28.         << a << "x^2 +" << ( b<0? "\b" : " " )
  29.         << b << "x +" << ( c<0? "\b" : " " )
  30.         << c << " = 0\" son:" << endl;
  31.  
  32.    cout << "X1 = " << x1 << endl;
  33.    cout << "X2 = " << x2 << endl;
  34.  
  35.    return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement