Advertisement
dllbridge

Untitled

Feb 8th, 2024
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include <iostream>
  5. #include   <math.h>
  6. using namespace std;
  7.  
  8. int a,                                              //  uhiuhiuhiu
  9.     b,                                              //  uiguyigig
  10.     c;                                              //  jkhkjhkjhkjh
  11.  
  12. int discriminant();    
  13.  
  14.  
  15. ///////////////////////////////////////////////////////
  16. int main()
  17. {
  18.  
  19.  
  20.     setlocale(LC_ALL, "rus");
  21.    
  22.     cout << "Введите через пробел коэффициенты A, B и C: ";
  23.     cin >> a >> b >> c;
  24.    
  25.     int D = discriminant();
  26.    
  27.     if(D  < 0)
  28.     {
  29.        cout << "У этого уравнения нет решений! (D = " << D << ")\n";  
  30.     }
  31.    
  32.     float x1, x2;
  33.    
  34.     if(D == 0)
  35.     {    
  36.    
  37.        x1 = -1 * b/(2*a);
  38.  
  39.        cout << "x1 = " << x1 << endl;
  40.     }
  41.    
  42.  
  43.     if(D > 0)
  44.     {    
  45.    
  46.        x1 = ( -1*b + sqrt(D) ) / (2 * a);
  47.        cout << "x1 = " << x1 << " ";
  48.        
  49.        x2 = ( -1*b - sqrt(D) ) / (2 * a);
  50.        cout << "x2 = " << x2 << endl;      
  51.        
  52.        
  53.     }  
  54. return 0;
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. /////////////////////////////////////////////////////////
  62. int discriminant()                                     //
  63. {
  64.    
  65.     int p1 =   b*b;
  66.     int p2 = 4*a*c;
  67.    
  68. return p1 - p2;
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement