Sclafus

Risolutore equazioni 2° grado

Nov 10th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     cout << "Risolutore equazioni di secondo grado" << endl;
  8.  
  9.     cout << "Inserire A: " << endl;
  10.     int a;
  11.     cin >> a;
  12.  
  13.     cout << "Inserire B: " << endl;
  14.     int b;
  15.     cin >> b;
  16.  
  17.     cout << "Inserire C: " << endl;
  18.     int c;
  19.     cin >> c;
  20.  
  21.     double delta = pow(b, 2) - 4 * a * c;
  22.     double sqrt_delta = pow(delta, 0.5);
  23.  
  24.     if (delta == 0) {
  25.         int x1;
  26.         x1 = -b / 2 * a;
  27.         cout << "x = " << x1 << endl;
  28.  
  29.     } else if (delta < 0) {
  30.         cout << "L'equazione non ha soluzioni" << endl;
  31.  
  32.  
  33.     } else {
  34.         int x1, x2;
  35.         x1 = (-b + sqrt_delta) / (2 * a);
  36.         x2 = (-b - sqrt_delta) / (2 * a);
  37.         cout << "x1 = " << x1 << endl;
  38.         cout << "x2 = " << x2 << endl;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment