DMG

Kvadratna jednacina

DMG
Mar 8th, 2012
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.     using namespace std;
  4.     main()
  5. {
  6.     float a, b, c, D, xim, x1, x2, x3, x4, m, s1, s2, t;
  7.     cin  >>  a  >>  b  >>  c;
  8.     D = b*b - 4*a*c;
  9.     if (D<0)
  10.         {
  11.         xim = sqrt(abs(D));
  12.         t = ((-1)*b)/(2*a);
  13.         m = xim/(2*a);
  14.         cout  <<  "t1 = "  <<  t  <<  " + j"  <<  m << endl;
  15.         cout  <<  "t2 = "  <<  t  <<  " - j"  <<  m  << endl;
  16.         }
  17.         else if  (D>=0)
  18.             {
  19.             s1 = ((-1)*b)/(2*a);
  20.             s2 = (sqrt(abs(D)))/(2*a);
  21.             if (s1 + s2 < 0)
  22.                 {
  23.                 x1 = sqrt (abs(s1+s2));
  24.                 cout << "x1 =  j" << x1 << endl;
  25.                 cout << "x2 = -j" << x1 << endl;
  26.                 }
  27.                     else
  28.                         {
  29.                         x1 = sqrt (s1+s2);
  30.                         x2 = (-1) * x1;
  31.                         cout << "x1 = " << x1 << endl;
  32.                         cout << "x2 = " << x2 << endl;
  33.                         }
  34.             if (s1 - s2 < 0)
  35.                 {
  36.                 x3 = sqrt (abs(s1-s2));
  37.                 cout << "x3 =  j" << x3 << endl;
  38.                 cout << "x4 = -j" << x3 << endl;
  39.                 }
  40.                     else
  41.                         {
  42.                         x3 = sqrt (s1-s2);
  43.                         x4 = (-1) * x3;
  44.                         cout << "x3 = " << x3 << endl;
  45.                         cout << "x4 = " << x4 << endl;
  46.                         }
  47.                 }
  48.     system ("PAUSE");
  49. }
Advertisement
Add Comment
Please, Sign In to add comment