Advertisement
Eddie_1337

Radacinile ecuatiei de gradul II

Sep 18th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int a, b, c, delta, x1, x2;
  8.     cout << endl;
  9.     cout << "           Calculul ecuatiei de gradul II" << endl << endl << endl;
  10.     cout << " Introduceti coeficientii ecuatiei" << endl << endl;
  11.     cout << " ax^2 + bx + c = 0" << endl << endl;
  12.     cout << " a = "; cin >> a;
  13.     cout << " b = "; cin >> b;
  14.     cout << " c = "; cin >> c;
  15.     delta = b*b - 4 * a * c;
  16.     cout << endl;
  17.     if (delta < 0)
  18.         cout << "Ecuatia nu are solutii reale";
  19.     else {
  20.         cout << " Solutiile ecuatiei sunt:" << endl << endl;
  21.         if (delta == 0) {
  22.             cout << " x1 = x2 = ";
  23.             if (-b / 2 * a == (int)(-b / 2 * a))
  24.                 cout << -b / 2 * a;
  25.             else
  26.                 cout << -b << "/" << 2 * a;
  27.         }
  28.         else
  29.             if (sqrt(delta) == (int)(sqrt(delta)))
  30.                 if ((-b + sqrt(delta)) / 2 * a == (int)((-b + sqrt(delta)) / 2 * a)) {
  31.                     cout << " x1 = " << (-b + sqrt(delta)) / 2 * a << endl;
  32.                     cout << " x2 = " << (-b - sqrt(delta)) / 2 * a;
  33.                 }
  34.                 else {
  35.                     cout << " x1 = " << -b + sqrt(delta) << "/" << 2 * a << endl;;
  36.                     cout << " x2 = " << -b - sqrt(delta) << "/" << 2 * a;
  37.                 }
  38.             else
  39.                 if (-b / 2 * a == (int)(-b / 2 * a)) {
  40.                     cout << " x1 = " << -b / 2 * a << " + rad(" << delta << ") / " << 2 * a << endl;
  41.                     cout << " x2 = " << -b / 2 * a << " - rad(" << delta << ") / " << 2 * a;
  42.                 }
  43.                 else {
  44.                     cout << " x1 = " << b << " + rad(" << delta << ") / " << 2 * a << endl;
  45.                     cout << " x2 = " << b << " - rad(" << delta << ") / " << 2 * a;
  46.                 }
  47.     }
  48.     cout << endl << endl;
  49.     cout << ' ';
  50.     system("pause");
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement